@samitouri / QOS-React-2 / commits / 2787eebe52

Clean up disableDOMTestUtils (#29610)

`disableDOMTestUtils` and the FB build `ReactTestUtilsFB` allowed us to finish migrating internal callsites off of ReactTestUtils. Now that usage is cleaned up, we can remove the flag, build artifact, and test coverage for the deprecated utility methods.

Jack Pope committed May 28, 2024 at 19:55 UTC 2787eebe52864356252a280fd811cd9d52807a82
11 files changed +1 -1640
packages/react-dom/src/__tests__/ReactTestUtils-test.js deleted
-735
@@ -1,735 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @emails react-core
8 - */
9 -
10 -'use strict';
11 -
12 -let React;
13 -let ReactDOMClient;
14 -let ReactDOMServer;
15 -let ReactTestUtils;
16 -let act;
17 -
18 -function getTestDocument(markup) {
19 - const doc = document.implementation.createHTMLDocument('');
20 - doc.open();
21 - doc.write(
22 - markup ||
23 - '<!doctype html><html><meta charset=utf-8><title>test doc</title>',
24 - );
25 - doc.close();
26 - return doc;
27 -}
28 -
29 -describe('ReactTestUtils', () => {
30 - beforeEach(() => {
31 - React = require('react');
32 - ReactDOMClient = require('react-dom/client');
33 - ReactDOMServer = require('react-dom/server');
34 - ReactTestUtils = require('react-dom/test-utils');
35 - act = require('internal-test-utils').act;
36 - });
37 -
38 - // @gate !disableDOMTestUtils
39 - it('Simulate should have locally attached media events', () => {
40 - expect(Object.keys(ReactTestUtils.Simulate).sort()).toMatchInlineSnapshot(`
41 - [
42 - "abort",
43 - "animationEnd",
44 - "animationIteration",
45 - "animationStart",
46 - "auxClick",
47 - "beforeInput",
48 - "beforeToggle",
49 - "blur",
50 - "canPlay",
51 - "canPlayThrough",
52 - "cancel",
53 - "change",
54 - "click",
55 - "close",
56 - "compositionEnd",
57 - "compositionStart",
58 - "compositionUpdate",
59 - "contextMenu",
60 - "copy",
61 - "cut",
62 - "doubleClick",
63 - "drag",
64 - "dragEnd",
65 - "dragEnter",
66 - "dragExit",
67 - "dragLeave",
68 - "dragOver",
69 - "dragStart",
70 - "drop",
71 - "durationChange",
72 - "emptied",
73 - "encrypted",
74 - "ended",
75 - "error",
76 - "focus",
77 - "gotPointerCapture",
78 - "input",
79 - "invalid",
80 - "keyDown",
81 - "keyPress",
82 - "keyUp",
83 - "load",
84 - "loadStart",
85 - "loadedData",
86 - "loadedMetadata",
87 - "lostPointerCapture",
88 - "mouseDown",
89 - "mouseEnter",
90 - "mouseLeave",
91 - "mouseMove",
92 - "mouseOut",
93 - "mouseOver",
94 - "mouseUp",
95 - "paste",
96 - "pause",
97 - "play",
98 - "playing",
99 - "pointerCancel",
100 - "pointerDown",
101 - "pointerEnter",
102 - "pointerLeave",
103 - "pointerMove",
104 - "pointerOut",
105 - "pointerOver",
106 - "pointerUp",
107 - "progress",
108 - "rateChange",
109 - "reset",
110 - "resize",
111 - "scroll",
112 - "seeked",
113 - "seeking",
114 - "select",
115 - "stalled",
116 - "submit",
117 - "suspend",
118 - "timeUpdate",
119 - "toggle",
120 - "touchCancel",
121 - "touchEnd",
122 - "touchMove",
123 - "touchStart",
124 - "transitionCancel",
125 - "transitionEnd",
126 - "transitionRun",
127 - "transitionStart",
128 - "volumeChange",
129 - "waiting",
130 - "wheel",
131 - ]
132 - `);
133 - });
134 -
135 - // @gate !disableDOMTestUtils
136 - it('gives Jest mocks a passthrough implementation with mockComponent()', async () => {
137 - class MockedComponent extends React.Component {
138 - render() {
139 - throw new Error('Should not get here.');
140 - }
141 - }
142 - // This is close enough to what a Jest mock would give us.
143 - MockedComponent.prototype.render = jest.fn();
144 -
145 - // Patch it up so it returns its children.
146 - expect(() => ReactTestUtils.mockComponent(MockedComponent)).toWarnDev(
147 - 'ReactTestUtils.mockComponent() is deprecated. ' +
148 - 'Use shallow rendering or jest.mock() instead.\n\n' +
149 - 'See https://react.dev/link/test-utils-mock-component for more information.',
150 - {withoutStack: true},
151 - );
152 -
153 - // De-duplication check
154 - ReactTestUtils.mockComponent(MockedComponent);
155 -
156 - const container = document.createElement('div');
157 - const root = ReactDOMClient.createRoot(container);
158 - await act(() => {
159 - root.render(<MockedComponent>Hello</MockedComponent>);
160 - });
161 -
162 - expect(container.textContent).toBe('Hello');
163 - });
164 -
165 - // @gate !disableDOMTestUtils
166 - it('can scryRenderedComponentsWithType', async () => {
167 - class Child extends React.Component {
168 - render() {
169 - return null;
170 - }
171 - }
172 - class Wrapper extends React.Component {
173 - render() {
174 - return (
175 - <div>
176 - <Child />
177 - </div>
178 - );
179 - }
180 - }
181 - const container = document.createElement('div');
182 - const root = ReactDOMClient.createRoot(container);
183 - let renderedComponent;
184 - await act(() => {
185 - root.render(<Wrapper ref={current => (renderedComponent = current)} />);
186 - });
187 - const scryResults = ReactTestUtils.scryRenderedComponentsWithType(
188 - renderedComponent,
189 - Child,
190 - );
191 - expect(scryResults.length).toBe(1);
192 - });
193 -
194 - // @gate !disableDOMTestUtils
195 - it('can scryRenderedDOMComponentsWithClass with TextComponent', async () => {
196 - class Wrapper extends React.Component {
197 - render() {
198 - return (
199 - <div>
200 - Hello <span>Jim</span>
201 - </div>
202 - );
203 - }
204 - }
205 -
206 - const container = document.createElement('div');
207 - const root = ReactDOMClient.createRoot(container);
208 - let renderedComponent;
209 - await act(() => {
210 - root.render(<Wrapper ref={current => (renderedComponent = current)} />);
211 - });
212 - const scryResults = ReactTestUtils.scryRenderedDOMComponentsWithClass(
213 - renderedComponent,
214 - 'NonExistentClass',
215 - );
216 - expect(scryResults.length).toBe(0);
217 - });
218 -
219 - // @gate !disableDOMTestUtils
220 - it('can scryRenderedDOMComponentsWithClass with className contains \\n', async () => {
221 - class Wrapper extends React.Component {
222 - render() {
223 - return (
224 - <div>
225 - Hello <span className={'x\ny'}>Jim</span>
226 - </div>
227 - );
228 - }
229 - }
230 -
231 - const container = document.createElement('div');
232 - const root = ReactDOMClient.createRoot(container);
233 - let renderedComponent;
234 - await act(() => {
235 - root.render(<Wrapper ref={current => (renderedComponent = current)} />);
236 - });
237 - const scryResults = ReactTestUtils.scryRenderedDOMComponentsWithClass(
238 - renderedComponent,
239 - 'x',
240 - );
241 - expect(scryResults.length).toBe(1);
242 - });
243 -
244 - // @gate !disableDOMTestUtils
245 - it('can scryRenderedDOMComponentsWithClass with multiple classes', async () => {
246 - class Wrapper extends React.Component {
247 - render() {
248 - return (
249 - <div>
250 - Hello <span className={'x y z'}>Jim</span>
251 - </div>
252 - );
253 - }
254 - }
255 -
256 - const container = document.createElement('div');
257 - const root = ReactDOMClient.createRoot(container);
258 - let renderedComponent;
259 - await act(() => {
260 - root.render(<Wrapper ref={current => (renderedComponent = current)} />);
261 - });
262 - const scryResults1 = ReactTestUtils.scryRenderedDOMComponentsWithClass(
263 - renderedComponent,
264 - 'x y',
265 - );
266 - expect(scryResults1.length).toBe(1);
267 -
268 - const scryResults2 = ReactTestUtils.scryRenderedDOMComponentsWithClass(
269 - renderedComponent,
270 - 'x z',
271 - );
272 - expect(scryResults2.length).toBe(1);
273 -
274 - const scryResults3 = ReactTestUtils.scryRenderedDOMComponentsWithClass(
275 - renderedComponent,
276 - ['x', 'y'],
277 - );
278 - expect(scryResults3.length).toBe(1);
279 -
280 - expect(scryResults1[0]).toBe(scryResults2[0]);
281 - expect(scryResults1[0]).toBe(scryResults3[0]);
282 -
283 - const scryResults4 = ReactTestUtils.scryRenderedDOMComponentsWithClass(
284 - renderedComponent,
285 - ['x', 'a'],
286 - );
287 - expect(scryResults4.length).toBe(0);
288 -
289 - const scryResults5 = ReactTestUtils.scryRenderedDOMComponentsWithClass(
290 - renderedComponent,
291 - ['x a'],
292 - );
293 - expect(scryResults5.length).toBe(0);
294 - });
295 -
296 - // @gate !disableDOMTestUtils
297 - it('traverses children in the correct order', async () => {
298 - class Wrapper extends React.Component {
299 - render() {
300 - return <div>{this.props.children}</div>;
301 - }
302 - }
303 -
304 - const container = document.createElement('div');
305 - const root = ReactDOMClient.createRoot(container);
306 - await act(() => {
307 - root.render(
308 - <Wrapper>
309 - {null}
310 - <div>purple</div>
311 - </Wrapper>,
312 - );
313 - });
314 - let tree;
315 - await act(() => {
316 - root.render(
317 - <Wrapper ref={current => (tree = current)}>
318 - <div>orange</div>
319 - <div>purple</div>
320 - </Wrapper>,
321 - );
322 - });
323 -
324 - const log = [];
325 - ReactTestUtils.findAllInRenderedTree(tree, function (child) {
326 - if (ReactTestUtils.isDOMComponent(child)) {
327 - log.push(child.textContent);
328 - }
329 - });
330 -
331 - // Should be document order, not mount order (which would be purple, orange)
332 - expect(log).toEqual(['orangepurple', 'orange', 'purple']);
333 - });
334 -
335 - // @gate !disableDOMTestUtils
336 - it('should support injected wrapper components as DOM components', async () => {
337 - const injectedDOMComponents = [
338 - 'button',
339 - 'form',
340 - 'iframe',
341 - 'img',
342 - 'input',
343 - 'option',
344 - 'select',
345 - 'textarea',
346 - ];
347 -
348 - // eslint-disable-next-line no-for-of-loops/no-for-of-loops
349 - for (const type of injectedDOMComponents) {
350 - const container = document.createElement('div');
351 - const root = ReactDOMClient.createRoot(container);
352 - let testComponent;
353 - await act(() => {
354 - root.render(
355 - React.createElement(type, {
356 - ref: current => (testComponent = current),
357 - }),
358 - );
359 - });
360 -
361 - expect(testComponent.tagName).toBe(type.toUpperCase());
362 - expect(ReactTestUtils.isDOMComponent(testComponent)).toBe(true);
363 - }
364 -
365 - // Full-page components (html, head, body) can't be rendered into a div
366 - // directly...
367 - class Root extends React.Component {
368 - htmlRef = React.createRef();
369 - headRef = React.createRef();
370 - bodyRef = React.createRef();
371 -
372 - render() {
373 - return (
374 - <html ref={this.htmlRef}>
375 - <head ref={this.headRef}>
376 - <title>hello</title>
377 - </head>
378 - <body ref={this.bodyRef}>hello, world</body>
379 - </html>
380 - );
381 - }
382 - }
383 -
384 - const markup = ReactDOMServer.renderToString(<Root />);
385 - const testDocument = getTestDocument(markup);
386 - let component;
387 - await act(() => {
388 - ReactDOMClient.hydrateRoot(
389 - testDocument,
390 - <Root ref={current => (component = current)} />,
391 - );
392 - });
393 -
394 - expect(component.htmlRef.current.tagName).toBe('HTML');
395 - expect(component.headRef.current.tagName).toBe('HEAD');
396 - expect(component.bodyRef.current.tagName).toBe('BODY');
397 - expect(ReactTestUtils.isDOMComponent(component.htmlRef.current)).toBe(true);
398 - expect(ReactTestUtils.isDOMComponent(component.headRef.current)).toBe(true);
399 - expect(ReactTestUtils.isDOMComponent(component.bodyRef.current)).toBe(true);
400 - });
401 -
402 - // @gate !disableDOMTestUtils
403 - it('can scry with stateless components involved', async () => {
404 - const Function = () => (
405 - <div>
406 - <hr />
407 - </div>
408 - );
409 -
410 - class SomeComponent extends React.Component {
411 - render() {
412 - return (
413 - <div>
414 - <Function />
415 - <hr />
416 - </div>
417 - );
418 - }
419 - }
420 -
421 - const container = document.createElement('div');
422 - const root = ReactDOMClient.createRoot(container);
423 - let inst;
424 - await act(() => {
425 - root.render(<SomeComponent ref={current => (inst = current)} />);
426 - });
427 -
428 - const hrs = ReactTestUtils.scryRenderedDOMComponentsWithTag(inst, 'hr');
429 - expect(hrs.length).toBe(2);
430 - });
431 -
432 - // @gate !disableDOMTestUtils
433 - it('provides a clear error when passing invalid objects to scry', () => {
434 - // This is probably too relaxed but it's existing behavior.
435 - ReactTestUtils.findAllInRenderedTree(null, 'span');
436 - ReactTestUtils.findAllInRenderedTree(undefined, 'span');
437 - ReactTestUtils.findAllInRenderedTree('', 'span');
438 - ReactTestUtils.findAllInRenderedTree(0, 'span');
439 - ReactTestUtils.findAllInRenderedTree(false, 'span');
440 -
441 - expect(() => {
442 - ReactTestUtils.findAllInRenderedTree([], 'span');
443 - }).toThrow(
444 - 'The first argument must be a React class instance. ' +
445 - 'Instead received: an array.',
446 - );
447 - expect(() => {
448 - ReactTestUtils.scryRenderedDOMComponentsWithClass(10, 'button');
449 - }).toThrow(
450 - 'The first argument must be a React class instance. ' +
451 - 'Instead received: 10.',
452 - );
453 - expect(() => {
454 - ReactTestUtils.findRenderedDOMComponentWithClass('hello', 'button');
455 - }).toThrow(
456 - 'The first argument must be a React class instance. ' +
457 - 'Instead received: hello.',
458 - );
459 - expect(() => {
460 - ReactTestUtils.scryRenderedDOMComponentsWithTag(
461 - {x: true, y: false},
462 - 'span',
463 - );
464 - }).toThrow(
465 - 'The first argument must be a React class instance. ' +
466 - 'Instead received: object with keys {x, y}.',
467 - );
468 - const div = document.createElement('div');
469 - expect(() => {
470 - ReactTestUtils.findRenderedDOMComponentWithTag(div, 'span');
471 - }).toThrow(
472 - 'The first argument must be a React class instance. ' +
473 - 'Instead received: a DOM node.',
474 - );
475 - expect(() => {
476 - ReactTestUtils.scryRenderedComponentsWithType(true, 'span');
477 - }).toThrow(
478 - 'The first argument must be a React class instance. ' +
479 - 'Instead received: true.',
480 - );
481 - expect(() => {
482 - ReactTestUtils.findRenderedComponentWithType(true, 'span');
483 - }).toThrow(
484 - 'The first argument must be a React class instance. ' +
485 - 'Instead received: true.',
486 - );
487 - });
488 -
489 - describe('Simulate', () => {
490 - // @gate !disableDOMTestUtils
491 - it('should change the value of an input field', async () => {
492 - const obj = {
493 - handler: function (e) {
494 - e.persist();
495 - },
496 - };
497 - spyOnDevAndProd(obj, 'handler');
498 - const container = document.createElement('div');
499 - const root = ReactDOMClient.createRoot(container);
500 - await act(() => {
501 - root.render(<input type="text" onChange={obj.handler} />);
502 - });
503 - const node = container.firstChild;
504 -
505 - node.value = 'giraffe';
506 - ReactTestUtils.Simulate.change(node);
507 -
508 - expect(obj.handler).toHaveBeenCalledWith(
509 - expect.objectContaining({target: node}),
510 - );
511 - });
512 -
513 - // @gate !disableDOMTestUtils
514 - it('should change the value of an input field in a component', async () => {
515 - class SomeComponent extends React.Component {
516 - inputRef = React.createRef();
517 - render() {
518 - return (
519 - <div>
520 - <input
521 - type="text"
522 - ref={this.inputRef}
523 - onChange={this.props.handleChange}
524 - />
525 - </div>
526 - );
527 - }
528 - }
529 -
530 - const obj = {
531 - handler: function (e) {
532 - e.persist();
533 - },
534 - };
535 - spyOnDevAndProd(obj, 'handler');
536 - const container = document.createElement('div');
537 - const root = ReactDOMClient.createRoot(container);
538 - let instance;
539 - await act(() => {
540 - root.render(
541 - <SomeComponent
542 - handleChange={obj.handler}
543 - ref={current => (instance = current)}
544 - />,
545 - );
546 - });
547 -
548 - const node = instance.inputRef.current;
549 - node.value = 'zebra';
550 - ReactTestUtils.Simulate.change(node);
551 -
552 - expect(obj.handler).toHaveBeenCalledWith(
553 - expect.objectContaining({target: node}),
554 - );
555 - });
556 -
557 - // @gate !disableDOMTestUtils
558 - it('should not warn when used with extra properties', async () => {
559 - const CLIENT_X = 100;
560 -
561 - class Component extends React.Component {
562 - childRef = React.createRef();
563 - handleClick = e => {
564 - expect(e.clientX).toBe(CLIENT_X);
565 - };
566 -
567 - render() {
568 - return <div onClick={this.handleClick} ref={this.childRef} />;
569 - }
570 - }
571 -
572 - const element = document.createElement('div');
573 - const root = ReactDOMClient.createRoot(element);
574 - let instance;
575 - await act(() => {
576 - root.render(<Component ref={current => (instance = current)} />);
577 - });
578 -
579 - ReactTestUtils.Simulate.click(instance.childRef.current, {
580 - clientX: CLIENT_X,
581 - });
582 - });
583 -
584 - // @gate !disableDOMTestUtils
585 - it('should set the type of the event', async () => {
586 - let event;
587 - const stub = jest.fn().mockImplementation(e => {
588 - e.persist();
589 - event = e;
590 - });
591 -
592 - const container = document.createElement('div');
593 - const root = ReactDOMClient.createRoot(container);
594 - let node;
595 - await act(() => {
596 - root.render(<div onKeyDown={stub} ref={current => (node = current)} />);
597 - });
598 -
599 - ReactTestUtils.Simulate.keyDown(node);
600 -
601 - expect(event.type).toBe('keydown');
602 - expect(event.nativeEvent.type).toBe('keydown');
603 - });
604 -
605 - // @gate !disableDOMTestUtils
606 - it('should work with renderIntoDocument', async () => {
607 - const onChange = jest.fn();
608 -
609 - class MyComponent extends React.Component {
610 - render() {
611 - return (
612 - <div>
613 - <input type="text" onChange={onChange} />
614 - </div>
615 - );
616 - }
617 - }
618 -
619 - const container = document.createElement('div');
620 - const root = ReactDOMClient.createRoot(container);
621 - let instance;
622 - await act(() => {
623 - root.render(<MyComponent ref={current => (instance = current)} />);
624 - });
625 -
626 - const input = ReactTestUtils.findRenderedDOMComponentWithTag(
627 - instance,
628 - 'input',
629 - );
630 - input.value = 'giraffe';
631 - ReactTestUtils.Simulate.change(input);
632 -
633 - expect(onChange).toHaveBeenCalledWith(
634 - expect.objectContaining({target: input}),
635 - );
636 - });
637 -
638 - // @gate !disableDOMTestUtils
639 - it('should have mouse enter simulated by test utils', async () => {
640 - const idCallOrder = [];
641 - const recordID = function (id) {
642 - idCallOrder.push(id);
643 - };
644 - let CHILD;
645 - function Child(props) {
646 - return (
647 - <div
648 - ref={current => (CHILD = current)}
649 - onMouseEnter={() => {
650 - recordID(CHILD);
651 - }}
652 - />
653 - );
654 - }
655 -
656 - class ChildWrapper extends React.PureComponent {
657 - render() {
658 - return <Child />;
659 - }
660 - }
661 -
662 - const container = document.createElement('div');
663 - const root = ReactDOMClient.createRoot(container);
664 - await act(() => {
665 - root.render(
666 - <div>
667 - <div>
668 - <ChildWrapper />
669 - <button disabled={true} />
670 - </div>
671 - </div>,
672 - );
673 - });
674 - await act(() => {
675 - ReactTestUtils.Simulate.mouseEnter(CHILD);
676 - });
677 - expect(idCallOrder).toEqual([CHILD]);
678 - });
679 - });
680 -
681 - // @gate !disableDOMTestUtils
682 - // @gate !disableLegacyMode
683 - it('should call setState callback with no arguments', async () => {
684 - let mockArgs;
685 - class Component extends React.Component {
686 - componentDidMount() {
687 - this.setState({}, (...args) => (mockArgs = args));
688 - }
689 - render() {
690 - return false;
691 - }
692 - }
693 -
694 - ReactTestUtils.renderIntoDocument(<Component />);
695 -
696 - expect(mockArgs.length).toEqual(0);
697 - });
698 -
699 - // @gate !disableDOMTestUtils
700 - it('should find rendered component with type in document', async () => {
701 - class MyComponent extends React.Component {
702 - render() {
703 - return true;
704 - }
705 - }
706 -
707 - const container = document.createElement('div');
708 - const root = ReactDOMClient.createRoot(container);
709 - let instance;
710 - await act(() => {
711 - root.render(<MyComponent ref={current => (instance = current)} />);
712 - });
713 -
714 - const renderedComponentType = ReactTestUtils.findRenderedComponentWithType(
715 - instance,
716 - MyComponent,
717 - );
718 -
719 - expect(renderedComponentType).toBe(instance);
720 - });
721 -
722 - // @gate __DEV__
723 - it('warns when using `act`', () => {
724 - expect(() => {
725 - ReactTestUtils.act(() => {});
726 - }).toErrorDev(
727 - [
728 - '`ReactDOMTestUtils.act` is deprecated in favor of `React.act`. ' +
729 - 'Import `act` from `react` instead of `react-dom/test-utils`. ' +
730 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
731 - ],
732 - {withoutStack: true},
733 - );
734 - });
735 -});
packages/react-dom/src/test-utils/ReactTestUtilsFB.js deleted
-884
@@ -1,884 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @noflow
8 - */
9 -
10 -import * as React from 'react';
11 -import * as ReactDOM from 'react-dom';
12 -import {findCurrentFiberUsingSlowPath} from 'react-reconciler/src/ReactFiberTreeReflection';
13 -import {get as getInstance} from 'shared/ReactInstanceMap';
14 -import {
15 - ClassComponent,
16 - FunctionComponent,
17 - HostComponent,
18 - HostHoistable,
19 - HostSingleton,
20 - HostText,
21 -} from 'react-reconciler/src/ReactWorkTags';
22 -import {SyntheticEvent} from 'react-dom-bindings/src/events/SyntheticEvent';
23 -import {ELEMENT_NODE} from 'react-dom-bindings/src/client/HTMLNodeType';
24 -import {disableDOMTestUtils} from 'shared/ReactFeatureFlags';
25 -import assign from 'shared/assign';
26 -import isArray from 'shared/isArray';
27 -
28 -// Keep in sync with ReactDOM.js:
29 -const SecretInternals =
30 - ReactDOM.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
31 -const EventInternals = SecretInternals.Events;
32 -const getInstanceFromNode = EventInternals[0];
33 -const getNodeFromInstance = EventInternals[1];
34 -const getFiberCurrentPropsFromNode = EventInternals[2];
35 -const enqueueStateRestore = EventInternals[3];
36 -const restoreStateIfNeeded = EventInternals[4];
37 -
38 -let didWarnAboutUsingAct = false;
39 -function act(callback) {
40 - if (didWarnAboutUsingAct === false) {
41 - didWarnAboutUsingAct = true;
42 - console.error(
43 - '`ReactDOMTestUtils.act` is deprecated in favor of `React.act`. ' +
44 - 'Import `act` from `react` instead of `react-dom/test-utils`. ' +
45 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
46 - );
47 - }
48 - return React.act(callback);
49 -}
50 -
51 -function Event(suffix) {}
52 -
53 -let hasWarnedAboutDeprecatedMockComponent = false;
54 -
55 -/**
56 - * @class ReactTestUtils
57 - */
58 -
59 -function findAllInRenderedFiberTreeInternal(fiber, test) {
60 - if (!fiber) {
61 - return [];
62 - }
63 - const currentParent = findCurrentFiberUsingSlowPath(fiber);
64 - if (!currentParent) {
65 - return [];
66 - }
67 - let node = currentParent;
68 - const ret = [];
69 - while (true) {
70 - if (
71 - node.tag === HostComponent ||
72 - node.tag === HostText ||
73 - node.tag === ClassComponent ||
74 - node.tag === FunctionComponent ||
75 - node.tag === HostHoistable ||
76 - node.tag === HostSingleton
77 - ) {
78 - const publicInst = node.stateNode;
79 - if (test(publicInst)) {
80 - ret.push(publicInst);
81 - }
82 - }
83 - if (node.child) {
84 - node.child.return = node;
85 - node = node.child;
86 - continue;
87 - }
88 - if (node === currentParent) {
89 - return ret;
90 - }
91 - while (!node.sibling) {
92 - if (!node.return || node.return === currentParent) {
93 - return ret;
94 - }
95 - node = node.return;
96 - }
97 - node.sibling.return = node.return;
98 - node = node.sibling;
99 - }
100 -}
101 -
102 -function validateClassInstance(inst, methodName) {
103 - if (!inst) {
104 - // This is probably too relaxed but it's existing behavior.
105 - return;
106 - }
107 - if (getInstance(inst)) {
108 - // This is a public instance indeed.
109 - return;
110 - }
111 - let received;
112 - const stringified = String(inst);
113 - if (isArray(inst)) {
114 - received = 'an array';
115 - } else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
116 - received = 'a DOM node';
117 - } else if (stringified === '[object Object]') {
118 - received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
119 - } else {
120 - received = stringified;
121 - }
122 -
123 - throw new Error(
124 - `The first argument must be a React class instance. ` +
125 - `Instead received: ${received}.`,
126 - );
127 -}
128 -
129 -/**
130 - * Utilities for making it easy to test React components.
131 - *
132 - * See https://reactjs.org/docs/test-utils.html
133 - *
134 - * Todo: Support the entire DOM.scry query syntax. For now, these simple
135 - * utilities will suffice for testing purposes.
136 - * @lends ReactTestUtils
137 - */
138 -function renderIntoDocument(element) {
139 - if (disableDOMTestUtils) {
140 - throw new Error(
141 - '`renderIntoDocument` was removed from `react-dom/test-utils`. ' +
142 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
143 - );
144 - }
145 -
146 - const div = document.createElement('div');
147 - // None of our tests actually require attaching the container to the
148 - // DOM, and doing so creates a mess that we rely on test isolation to
149 - // clean up, so we're going to stop honoring the name of this method
150 - // (and probably rename it eventually) if no problems arise.
151 - // document.documentElement.appendChild(div);
152 - return ReactDOM.render(element, div);
153 -}
154 -
155 -function isElement(element) {
156 - if (disableDOMTestUtils) {
157 - throw new Error(
158 - '`isElement` was removed from `react-dom/test-utils`. ' +
159 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
160 - );
161 - }
162 -
163 - return React.isValidElement(element);
164 -}
165 -
166 -function isElementOfType(inst, convenienceConstructor) {
167 - if (disableDOMTestUtils) {
168 - throw new Error(
169 - '`isElementOfType` was removed from `react-dom/test-utils`. ' +
170 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
171 - );
172 - }
173 -
174 - return React.isValidElement(inst) && inst.type === convenienceConstructor;
175 -}
176 -
177 -function isDOMComponent(inst) {
178 - if (disableDOMTestUtils) {
179 - throw new Error(
180 - '`isDOMComponent` was removed from `react-dom/test-utils`. ' +
181 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
182 - );
183 - }
184 -
185 - return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
186 -}
187 -
188 -function isDOMComponentElement(inst) {
189 - if (disableDOMTestUtils) {
190 - throw new Error(
191 - '`isDOMComponentElement` was removed from `react-dom/test-utils`. ' +
192 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
193 - );
194 - }
195 -
196 - return !!(inst && React.isValidElement(inst) && !!inst.tagName);
197 -}
198 -
199 -function isCompositeComponent(inst) {
200 - if (disableDOMTestUtils) {
201 - throw new Error(
202 - '`isCompositeComponent` was removed from `react-dom/test-utils`. ' +
203 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
204 - );
205 - }
206 -
207 - if (isDOMComponent(inst)) {
208 - // Accessing inst.setState warns; just return false as that'll be what
209 - // this returns when we have DOM nodes as refs directly
210 - return false;
211 - }
212 - return (
213 - inst != null &&
214 - typeof inst.render === 'function' &&
215 - typeof inst.setState === 'function'
216 - );
217 -}
218 -
219 -function isCompositeComponentWithType(inst, type) {
220 - if (disableDOMTestUtils) {
221 - throw new Error(
222 - '`isCompositeComponentWithType` was removed from `react-dom/test-utils`. ' +
223 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
224 - );
225 - }
226 -
227 - if (!isCompositeComponent(inst)) {
228 - return false;
229 - }
230 - const internalInstance = getInstance(inst);
231 - const constructor = internalInstance.type;
232 - return constructor === type;
233 -}
234 -
235 -function findAllInRenderedTree(inst, test) {
236 - if (disableDOMTestUtils) {
237 - throw new Error(
238 - '`findAllInRenderedTree` was removed from `react-dom/test-utils`. ' +
239 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
240 - );
241 - }
242 -
243 - validateClassInstance(inst, 'findAllInRenderedTree');
244 - if (!inst) {
245 - return [];
246 - }
247 - const internalInstance = getInstance(inst);
248 - return findAllInRenderedFiberTreeInternal(internalInstance, test);
249 -}
250 -
251 -/**
252 - * Finds all instances of components in the rendered tree that are DOM
253 - * components with the class name matching `className`.
254 - * @return {array} an array of all the matches.
255 - */
256 -function scryRenderedDOMComponentsWithClass(root, classNames) {
257 - if (disableDOMTestUtils) {
258 - throw new Error(
259 - '`scryRenderedDOMComponentsWithClass` was removed from `react-dom/test-utils`. ' +
260 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
261 - );
262 - }
263 -
264 - validateClassInstance(root, 'scryRenderedDOMComponentsWithClass');
265 - return findAllInRenderedTree(root, function (inst) {
266 - if (isDOMComponent(inst)) {
267 - let className = inst.className;
268 - if (typeof className !== 'string') {
269 - // SVG, probably.
270 - className = inst.getAttribute('class') || '';
271 - }
272 - const classList = className.split(/\s+/);
273 -
274 - if (!isArray(classNames)) {
275 - if (classNames === undefined) {
276 - throw new Error(
277 - 'TestUtils.scryRenderedDOMComponentsWithClass expects a ' +
278 - 'className as a second argument.',
279 - );
280 - }
281 -
282 - classNames = classNames.split(/\s+/);
283 - }
284 - return classNames.every(function (name) {
285 - return classList.indexOf(name) !== -1;
286 - });
287 - }
288 - return false;
289 - });
290 -}
291 -
292 -/**
293 - * Like scryRenderedDOMComponentsWithClass but expects there to be one result,
294 - * and returns that one result, or throws exception if there is any other
295 - * number of matches besides one.
296 - * @return {!ReactDOMComponent} The one match.
297 - */
298 -function findRenderedDOMComponentWithClass(root, className) {
299 - if (disableDOMTestUtils) {
300 - throw new Error(
301 - '`findRenderedDOMComponentWithClass` was removed from `react-dom/test-utils`. ' +
302 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
303 - );
304 - }
305 -
306 - validateClassInstance(root, 'findRenderedDOMComponentWithClass');
307 - const all = scryRenderedDOMComponentsWithClass(root, className);
308 - if (all.length !== 1) {
309 - throw new Error(
310 - 'Did not find exactly one match (found: ' +
311 - all.length +
312 - ') ' +
313 - 'for class:' +
314 - className,
315 - );
316 - }
317 - return all[0];
318 -}
319 -
320 -/**
321 - * Finds all instances of components in the rendered tree that are DOM
322 - * components with the tag name matching `tagName`.
323 - * @return {array} an array of all the matches.
324 - */
325 -function scryRenderedDOMComponentsWithTag(root, tagName) {
326 - if (disableDOMTestUtils) {
327 - throw new Error(
328 - '`scryRenderedDOMComponentsWithTag` was removed from `react-dom/test-utils`. ' +
329 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
330 - );
331 - }
332 -
333 - validateClassInstance(root, 'scryRenderedDOMComponentsWithTag');
334 - return findAllInRenderedTree(root, function (inst) {
335 - return (
336 - isDOMComponent(inst) &&
337 - inst.tagName.toUpperCase() === tagName.toUpperCase()
338 - );
339 - });
340 -}
341 -
342 -/**
343 - * Like scryRenderedDOMComponentsWithTag but expects there to be one result,
344 - * and returns that one result, or throws exception if there is any other
345 - * number of matches besides one.
346 - * @return {!ReactDOMComponent} The one match.
347 - */
348 -function findRenderedDOMComponentWithTag(root, tagName) {
349 - if (disableDOMTestUtils) {
350 - throw new Error(
351 - '`findRenderedDOMComponentWithTag` was removed from `react-dom/test-utils`. ' +
352 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
353 - );
354 - }
355 -
356 - validateClassInstance(root, 'findRenderedDOMComponentWithTag');
357 - const all = scryRenderedDOMComponentsWithTag(root, tagName);
358 - if (all.length !== 1) {
359 - throw new Error(
360 - 'Did not find exactly one match (found: ' +
361 - all.length +
362 - ') ' +
363 - 'for tag:' +
364 - tagName,
365 - );
366 - }
367 - return all[0];
368 -}
369 -
370 -/**
371 - * Finds all instances of components with type equal to `componentType`.
372 - * @return {array} an array of all the matches.
373 - */
374 -function scryRenderedComponentsWithType(root, componentType) {
375 - if (disableDOMTestUtils) {
376 - throw new Error(
377 - '`scryRenderedComponentsWithType` was removed from `react-dom/test-utils`. ' +
378 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
379 - );
380 - }
381 -
382 - validateClassInstance(root, 'scryRenderedComponentsWithType');
383 - return findAllInRenderedTree(root, function (inst) {
384 - return isCompositeComponentWithType(inst, componentType);
385 - });
386 -}
387 -
388 -/**
389 - * Same as `scryRenderedComponentsWithType` but expects there to be one result
390 - * and returns that one result, or throws exception if there is any other
391 - * number of matches besides one.
392 - * @return {!ReactComponent} The one match.
393 - */
394 -function findRenderedComponentWithType(root, componentType) {
395 - if (disableDOMTestUtils) {
396 - throw new Error(
397 - '`findRenderedComponentWithType` was removed from `react-dom/test-utils`. ' +
398 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
399 - );
400 - }
401 -
402 - validateClassInstance(root, 'findRenderedComponentWithType');
403 - const all = scryRenderedComponentsWithType(root, componentType);
404 - if (all.length !== 1) {
405 - throw new Error(
406 - 'Did not find exactly one match (found: ' +
407 - all.length +
408 - ') ' +
409 - 'for componentType:' +
410 - componentType,
411 - );
412 - }
413 - return all[0];
414 -}
415 -
416 -/**
417 - * Pass a mocked component module to this method to augment it with
418 - * useful methods that allow it to be used as a dummy React component.
419 - * Instead of rendering as usual, the component will become a simple
420 - * <div> containing any provided children.
421 - *
422 - * @param {object} module the mock function object exported from a
423 - * module that defines the component to be mocked
424 - * @param {?string} mockTagName optional dummy root tag name to return
425 - * from render method (overrides
426 - * module.mockTagName if provided)
427 - * @return {object} the ReactTestUtils object (for chaining)
428 - */
429 -function mockComponent(module, mockTagName) {
430 - if (disableDOMTestUtils) {
431 - throw new Error(
432 - '`mockComponent` was removed from `react-dom/test-utils`. ' +
433 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
434 - );
435 - }
436 -
437 - if (__DEV__) {
438 - if (!hasWarnedAboutDeprecatedMockComponent) {
439 - hasWarnedAboutDeprecatedMockComponent = true;
440 - console.warn(
441 - 'ReactTestUtils.mockComponent() is deprecated. ' +
442 - 'Use shallow rendering or jest.mock() instead.\n\n' +
443 - 'See https://react.dev/link/test-utils-mock-component for more information.',
444 - );
445 - }
446 - }
447 -
448 - mockTagName = mockTagName || module.mockTagName || 'div';
449 -
450 - module.prototype.render.mockImplementation(function () {
451 - return React.createElement(mockTagName, null, this.props.children);
452 - });
453 -
454 - return this;
455 -}
456 -
457 -function nativeTouchData(x, y) {
458 - if (disableDOMTestUtils) {
459 - throw new Error(
460 - '`nativeTouchData` was removed from `react-dom/test-utils`. ' +
461 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
462 - );
463 - }
464 -
465 - return {
466 - touches: [{pageX: x, pageY: y}],
467 - };
468 -}
469 -
470 -// Start of inline: the below functions were inlined from
471 -// EventPropagator.js, as they deviated from ReactDOM's newer
472 -// implementations.
473 -
474 -let hasError: boolean = false;
475 -let caughtError: mixed = null;
476 -
477 -/**
478 - * Dispatch the event to the listener.
479 - * @param {SyntheticEvent} event SyntheticEvent to handle
480 - * @param {function} listener Application-level callback
481 - * @param {*} inst Internal component instance
482 - */
483 -function executeDispatch(event, listener, inst) {
484 - event.currentTarget = getNodeFromInstance(inst);
485 - try {
486 - listener(event);
487 - } catch (error) {
488 - if (!hasError) {
489 - hasError = true;
490 - caughtError = error;
491 - }
492 - }
493 - event.currentTarget = null;
494 -}
495 -
496 -/**
497 - * Standard/simple iteration through an event's collected dispatches.
498 - */
499 -function executeDispatchesInOrder(event) {
500 - const dispatchListeners = event._dispatchListeners;
501 - const dispatchInstances = event._dispatchInstances;
502 - if (isArray(dispatchListeners)) {
503 - for (let i = 0; i < dispatchListeners.length; i++) {
504 - if (event.isPropagationStopped()) {
505 - break;
506 - }
507 - // Listeners and Instances are two parallel arrays that are always in sync.
508 - executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
509 - }
510 - } else if (dispatchListeners) {
511 - executeDispatch(event, dispatchListeners, dispatchInstances);
512 - }
513 - event._dispatchListeners = null;
514 - event._dispatchInstances = null;
515 -}
516 -
517 -/**
518 - * Dispatches an event and releases it back into the pool, unless persistent.
519 - *
520 - * @param {?object} event Synthetic event to be dispatched.
521 - * @private
522 - */
523 -function executeDispatchesAndRelease(event /* ReactSyntheticEvent */) {
524 - if (event) {
525 - executeDispatchesInOrder(event);
526 -
527 - if (!event.isPersistent()) {
528 - event.constructor.release(event);
529 - }
530 - }
531 -}
532 -
533 -function isInteractive(tag) {
534 - return (
535 - tag === 'button' ||
536 - tag === 'input' ||
537 - tag === 'select' ||
538 - tag === 'textarea'
539 - );
540 -}
541 -
542 -function getParent(inst) {
543 - do {
544 - inst = inst.return;
545 - // TODO: If this is a HostRoot we might want to bail out.
546 - // That is depending on if we want nested subtrees (layers) to bubble
547 - // events to their parent. We could also go through parentNode on the
548 - // host node but that wouldn't work for React Native and doesn't let us
549 - // do the portal feature.
550 - } while (inst && inst.tag !== HostComponent && inst.tag !== HostSingleton);
551 - if (inst) {
552 - return inst;
553 - }
554 - return null;
555 -}
556 -
557 -/**
558 - * Simulates the traversal of a two-phase, capture/bubble event dispatch.
559 - */
560 -export function traverseTwoPhase(inst, fn, arg) {
561 - const path = [];
562 - while (inst) {
563 - path.push(inst);
564 - inst = getParent(inst);
565 - }
566 - let i;
567 - for (i = path.length; i-- > 0; ) {
568 - fn(path[i], 'captured', arg);
569 - }
570 - for (i = 0; i < path.length; i++) {
571 - fn(path[i], 'bubbled', arg);
572 - }
573 -}
574 -
575 -function shouldPreventMouseEvent(name, type, props) {
576 - switch (name) {
577 - case 'onClick':
578 - case 'onClickCapture':
579 - case 'onDoubleClick':
580 - case 'onDoubleClickCapture':
581 - case 'onMouseDown':
582 - case 'onMouseDownCapture':
583 - case 'onMouseMove':
584 - case 'onMouseMoveCapture':
585 - case 'onMouseUp':
586 - case 'onMouseUpCapture':
587 - case 'onMouseEnter':
588 - return !!(props.disabled && isInteractive(type));
589 - default:
590 - return false;
591 - }
592 -}
593 -
594 -/**
595 - * @param {object} inst The instance, which is the source of events.
596 - * @param {string} registrationName Name of listener (e.g. `onClick`).
597 - * @return {?function} The stored callback.
598 - */
599 -function getListener(inst /* Fiber */, registrationName: string) {
600 - // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
601 - // live here; needs to be moved to a better place soon
602 - const stateNode = inst.stateNode;
603 - if (!stateNode) {
604 - // Work in progress (ex: onload events in incremental mode).
605 - return null;
606 - }
607 - const props = getFiberCurrentPropsFromNode(stateNode);
608 - if (!props) {
609 - // Work in progress.
610 - return null;
611 - }
612 - const listener = props[registrationName];
613 - if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
614 - return null;
615 - }
616 -
617 - if (listener && typeof listener !== 'function') {
618 - throw new Error(
619 - `Expected \`${registrationName}\` listener to be a function, instead got a value of \`${typeof listener}\` type.`,
620 - );
621 - }
622 -
623 - return listener;
624 -}
625 -
626 -function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) {
627 - let registrationName = event._reactName;
628 - if (propagationPhase === 'captured') {
629 - registrationName += 'Capture';
630 - }
631 - return getListener(inst, registrationName);
632 -}
633 -
634 -function accumulateDispatches(inst, ignoredDirection, event) {
635 - if (inst && event && event._reactName) {
636 - const registrationName = event._reactName;
637 - const listener = getListener(inst, registrationName);
638 - if (listener) {
639 - if (event._dispatchListeners == null) {
640 - event._dispatchListeners = [];
641 - }
642 - if (event._dispatchInstances == null) {
643 - event._dispatchInstances = [];
644 - }
645 - event._dispatchListeners.push(listener);
646 - event._dispatchInstances.push(inst);
647 - }
648 - }
649 -}
650 -
651 -function accumulateDirectionalDispatches(inst, phase, event) {
652 - if (__DEV__) {
653 - if (!inst) {
654 - console.error('Dispatching inst must not be null');
655 - }
656 - }
657 - const listener = listenerAtPhase(inst, event, phase);
658 - if (listener) {
659 - if (event._dispatchListeners == null) {
660 - event._dispatchListeners = [];
661 - }
662 - if (event._dispatchInstances == null) {
663 - event._dispatchInstances = [];
664 - }
665 - event._dispatchListeners.push(listener);
666 - event._dispatchInstances.push(inst);
667 - }
668 -}
669 -
670 -function accumulateDirectDispatchesSingle(event) {
671 - if (event && event._reactName) {
672 - accumulateDispatches(event._targetInst, null, event);
673 - }
674 -}
675 -
676 -function accumulateTwoPhaseDispatchesSingle(event) {
677 - if (event && event._reactName) {
678 - traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
679 - }
680 -}
681 -
682 -// End of inline
683 -
684 -const Simulate = {};
685 -
686 -const directDispatchEventTypes = new Set([
687 - 'mouseEnter',
688 - 'mouseLeave',
689 - 'pointerEnter',
690 - 'pointerLeave',
691 -]);
692 -
693 -/**
694 - * Exports:
695 - *
696 - * - `Simulate.click(Element)`
697 - * - `Simulate.mouseMove(Element)`
698 - * - `Simulate.change(Element)`
699 - * - ... (All keys from event plugin `eventTypes` objects)
700 - */
701 -function makeSimulator(eventType) {
702 - return function (domNode, eventData) {
703 - if (disableDOMTestUtils) {
704 - throw new Error(
705 - '`Simulate` was removed from `react-dom/test-utils`. ' +
706 - 'See https://react.dev/warnings/react-dom-test-utils for more info.',
707 - );
708 - }
709 -
710 - if (React.isValidElement(domNode)) {
711 - throw new Error(
712 - 'TestUtils.Simulate expected a DOM node as the first argument but received ' +
713 - 'a React element. Pass the DOM node you wish to simulate the event on instead. ' +
714 - 'Note that TestUtils.Simulate will not work if you are using shallow rendering.',
715 - );
716 - }
717 -
718 - if (isCompositeComponent(domNode)) {
719 - throw new Error(
720 - 'TestUtils.Simulate expected a DOM node as the first argument but received ' +
721 - 'a component instance. Pass the DOM node you wish to simulate the event on instead.',
722 - );
723 - }
724 -
725 - const reactName = 'on' + eventType[0].toUpperCase() + eventType.slice(1);
726 - const fakeNativeEvent = new Event();
727 - fakeNativeEvent.target = domNode;
728 - fakeNativeEvent.type = eventType.toLowerCase();
729 -
730 - const targetInst = getInstanceFromNode(domNode);
731 - const event = new SyntheticEvent(
732 - reactName,
733 - fakeNativeEvent.type,
734 - targetInst,
735 - fakeNativeEvent,
736 - domNode,
737 - );
738 -
739 - // Since we aren't using pooling, always persist the event. This will make
740 - // sure it's marked and won't warn when setting additional properties.
741 - event.persist();
742 - assign(event, eventData);
743 -
744 - if (directDispatchEventTypes.has(eventType)) {
745 - accumulateDirectDispatchesSingle(event);
746 - } else {
747 - accumulateTwoPhaseDispatchesSingle(event);
748 - }
749 -
750 - ReactDOM.unstable_batchedUpdates(function () {
751 - // Normally extractEvent enqueues a state restore, but we'll just always
752 - // do that since we're by-passing it here.
753 - enqueueStateRestore(domNode);
754 - executeDispatchesAndRelease(event);
755 - if (hasError) {
756 - const error = caughtError;
757 - hasError = false;
758 - caughtError = null;
759 - throw error;
760 - }
761 - });
762 - restoreStateIfNeeded();
763 - };
764 -}
765 -
766 -// A one-time snapshot with no plans to update. We'll probably want to deprecate Simulate API.
767 -const simulatedEventTypes = [
768 - 'blur',
769 - 'cancel',
770 - 'click',
771 - 'close',
772 - 'contextMenu',
773 - 'copy',
774 - 'cut',
775 - 'auxClick',
776 - 'doubleClick',
777 - 'dragEnd',
778 - 'dragStart',
779 - 'drop',
780 - 'focus',
781 - 'input',
782 - 'invalid',
783 - 'keyDown',
784 - 'keyPress',
785 - 'keyUp',
786 - 'mouseDown',
787 - 'mouseUp',
788 - 'paste',
789 - 'pause',
790 - 'play',
791 - 'pointerCancel',
792 - 'pointerDown',
793 - 'pointerUp',
794 - 'rateChange',
795 - 'reset',
796 - 'resize',
797 - 'seeked',
798 - 'submit',
799 - 'touchCancel',
800 - 'touchEnd',
801 - 'touchStart',
802 - 'volumeChange',
803 - 'drag',
804 - 'dragEnter',
805 - 'dragExit',
806 - 'dragLeave',
807 - 'dragOver',
808 - 'mouseMove',
809 - 'mouseOut',
810 - 'mouseOver',
811 - 'pointerMove',
812 - 'pointerOut',
813 - 'pointerOver',
814 - 'scroll',
815 - 'toggle',
816 - 'touchMove',
817 - 'wheel',
818 - 'abort',
819 - 'animationEnd',
820 - 'animationIteration',
821 - 'animationStart',
822 - 'canPlay',
823 - 'canPlayThrough',
824 - 'durationChange',
825 - 'emptied',
826 - 'encrypted',
827 - 'ended',
828 - 'error',
829 - 'gotPointerCapture',
830 - 'load',
831 - 'loadedData',
832 - 'loadedMetadata',
833 - 'loadStart',
834 - 'lostPointerCapture',
835 - 'playing',
836 - 'progress',
837 - 'seeking',
838 - 'stalled',
839 - 'suspend',
840 - 'timeUpdate',
841 - 'transitionRun',
842 - 'transitionStart',
843 - 'transitionCancel',
844 - 'transitionEnd',
845 - 'waiting',
846 - 'mouseEnter',
847 - 'mouseLeave',
848 - 'pointerEnter',
849 - 'pointerLeave',
850 - 'change',
851 - 'select',
852 - 'beforeInput',
853 - 'beforeToggle',
854 - 'compositionEnd',
855 - 'compositionStart',
856 - 'compositionUpdate',
857 -];
858 -function buildSimulators() {
859 - simulatedEventTypes.forEach(eventType => {
860 - Simulate[eventType] = makeSimulator(eventType);
861 - });
862 -}
863 -buildSimulators();
864 -
865 -export {
866 - renderIntoDocument,
867 - isElement,
868 - isElementOfType,
869 - isDOMComponent,
870 - isDOMComponentElement,
871 - isCompositeComponent,
872 - isCompositeComponentWithType,
873 - findAllInRenderedTree,
874 - scryRenderedDOMComponentsWithClass,
875 - findRenderedDOMComponentWithClass,
876 - scryRenderedDOMComponentsWithTag,
877 - findRenderedDOMComponentWithTag,
878 - scryRenderedComponentsWithType,
879 - findRenderedComponentWithType,
880 - mockComponent,
881 - nativeTouchData,
882 - Simulate,
883 - act,
884 -};
packages/react-dom/test-utils.fb.js deleted
-10
@@ -1,10 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -export * from './src/test-utils/ReactTestUtilsFB';
packages/shared/ReactFeatureFlags.js
-2
@@ -192,8 +192,6 @@ export const enableReactTestRendererWarning = true;
192 // before removing them in stable in the next Major
193 export const disableLegacyMode = true;
194
195 -export const disableDOMTestUtils = true;
196 -
195 // Make <Context> equivalent to <Context.Provider> instead of <Context.Consumer>
196 export const enableRenderableContext = true;
197
packages/shared/forks/ReactFeatureFlags.native-fb.js
-2
@@ -98,8 +98,6 @@ export const disableStringRefs = true;
98
99 export const enableReactTestRendererWarning = false;
100 export const disableLegacyMode = false;
101 -export const disableDOMTestUtils = false;
102 -
101 export const enableOwnerStacks = false;
102
103 // Flow magic to verify the exports of this file match the original version.
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -22,7 +22,6 @@ export const enableRefAsProp = __TODO_NEXT_RN_MAJOR__;
22 export const disableStringRefs = __TODO_NEXT_RN_MAJOR__;
23 export const enableFastJSX = __TODO_NEXT_RN_MAJOR__;
24 export const disableLegacyMode = __TODO_NEXT_RN_MAJOR__;
25 -export const disableDOMTestUtils = __TODO_NEXT_RN_MAJOR__;
25 export const useModernStrictMode = __TODO_NEXT_RN_MAJOR__;
26 export const enableReactTestRendererWarning = __TODO_NEXT_RN_MAJOR__;
27 export const enableAsyncActions = __TODO_NEXT_RN_MAJOR__;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -92,7 +92,6 @@ export const disableStringRefs = true;
92 export const enableFastJSX = true;
93 export const disableLegacyMode = true;
94 export const disableLegacyContext = true;
95 -export const disableDOMTestUtils = true;
95 export const enableRenderableContext = true;
96 export const enableReactTestRendererWarning = true;
97 export const disableDefaultPropsExceptForClasses = true;
packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js
-1
@@ -85,7 +85,6 @@ export const enableFastJSX = true;
85
86 export const enableReactTestRendererWarning = false;
87 export const disableLegacyMode = false;
88 -export const disableDOMTestUtils = false;
88
89 export const disableDefaultPropsExceptForClasses = false;
90 export const enableAddPropertiesFastPath = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -85,7 +85,6 @@ export const enableFastJSX = false;
85
86 export const enableReactTestRendererWarning = false;
87 export const disableLegacyMode = false;
88 -export const disableDOMTestUtils = false;
88
89 export const disableDefaultPropsExceptForClasses = false;
90 export const enableAddPropertiesFastPath = false;
packages/shared/forks/ReactFeatureFlags.www.js
-2
@@ -120,8 +120,6 @@ export const disableStringRefs = false;
120
121 export const disableLegacyMode = __EXPERIMENTAL__;
122
123 -export const disableDOMTestUtils = false;
124 -
123 export const enableOwnerStacks = false;
124
125 // Flow magic to verify the exports of this file match the original version.
scripts/rollup/bundles.js
+1 -1
@@ -231,7 +231,7 @@ const bundles = [
231 /******* Test Utils *******/
232 {
233 moduleType: RENDERER_UTILS,
234 - bundleTypes: [FB_WWW_DEV, NODE_DEV, NODE_PROD],
234 + bundleTypes: [NODE_DEV, NODE_PROD],
235 entry: 'react-dom/test-utils',
236 global: 'ReactTestUtils',
237 minifyWithProdErrorCodes: false,