@samitouri / QOS-React-2 / commits / 58cd0ef35d

Remove ReactTestUtils from ReactLegacyUpdates-test (#28531)

Sebastian Silbermann committed Mar 11, 2024 at 22:11 UTC 58cd0ef35decebd1f29609a25f12ca030bf40c97
1 file changed +48 -27
packages/react-dom/src/__tests__/ReactLegacyUpdates-test.js
+48 -27
@@ -11,7 +11,6 @@
11
12 let React;
13 let ReactDOM;
14 -let ReactTestUtils;
14 let act;
15 let Scheduler;
16 let assertLog;
@@ -23,7 +22,6 @@ describe('ReactLegacyUpdates', () => {
22 jest.resetModules();
23 React = require('react');
24 ReactDOM = require('react-dom');
26 - ReactTestUtils = require('react-dom/test-utils');
25 act = require('internal-test-utils').act;
26 Scheduler = require('scheduler');
27
@@ -47,7 +45,8 @@ describe('ReactLegacyUpdates', () => {
45 }
46 }
47
50 - const instance = ReactTestUtils.renderIntoDocument(<Component />);
48 + const container = document.createElement('div');
49 + const instance = ReactDOM.render(<Component />, container);
50 expect(instance.state.x).toBe(0);
51
52 ReactDOM.unstable_batchedUpdates(function () {
@@ -77,7 +76,8 @@ describe('ReactLegacyUpdates', () => {
76 }
77 }
78
80 - const instance = ReactTestUtils.renderIntoDocument(<Component />);
79 + const container = document.createElement('div');
80 + const instance = ReactDOM.render(<Component />, container);
81 expect(instance.state.x).toBe(0);
82 expect(instance.state.y).toBe(0);
83
@@ -163,7 +163,8 @@ describe('ReactLegacyUpdates', () => {
163 }
164 }
165
166 - const instance = ReactTestUtils.renderIntoDocument(<Parent />);
166 + const container = document.createElement('div');
167 + const instance = ReactDOM.render(<Parent />, container);
168 const child = instance.childRef.current;
169 expect(instance.state.x).toBe(0);
170 expect(child.state.y).toBe(0);
@@ -218,7 +219,8 @@ describe('ReactLegacyUpdates', () => {
219 }
220 }
221
221 - const instance = ReactTestUtils.renderIntoDocument(<Parent />);
222 + const container = document.createElement('div');
223 + const instance = ReactDOM.render(<Parent />, container);
224 const child = instance.childRef.current;
225 expect(instance.state.x).toBe(0);
226 expect(child.state.y).toBe(0);
@@ -256,7 +258,8 @@ describe('ReactLegacyUpdates', () => {
258 }
259 }
260
259 - const instance = ReactTestUtils.renderIntoDocument(<Component />);
261 + const container = document.createElement('div');
262 + const instance = ReactDOM.render(<Component />, container);
263 expect(instance.state.x).toBe(0);
264
265 let innerCallbackRun = false;
@@ -301,7 +304,8 @@ describe('ReactLegacyUpdates', () => {
304 }
305 }
306
304 - const instance = ReactTestUtils.renderIntoDocument(<Component />);
307 + const container = document.createElement('div');
308 + const instance = ReactDOM.render(<Component />, container);
309 expect(instance.state.x).toBe(0);
310
311 let callbacksRun = 0;
@@ -351,8 +355,8 @@ describe('ReactLegacyUpdates', () => {
355 expect(parentRenderCount).toBe(0);
356 expect(childRenderCount).toBe(0);
357
354 - let instance = <Parent />;
355 - instance = ReactTestUtils.renderIntoDocument(instance);
358 + const container = document.createElement('div');
359 + const instance = ReactDOM.render(<Parent />, container);
360
361 expect(parentRenderCount).toBe(1);
362 expect(childRenderCount).toBe(1);
@@ -405,7 +409,8 @@ describe('ReactLegacyUpdates', () => {
409 }
410 }
411
408 - ReactTestUtils.renderIntoDocument(<Top />);
412 + const container = document.createElement('div');
413 + ReactDOM.render(<Top />, container);
414 expect(numMiddleRenders).toBe(2);
415 expect(numBottomRenders).toBe(1);
416 });
@@ -478,8 +483,8 @@ describe('ReactLegacyUpdates', () => {
483 }
484 Object.assign(App.prototype, UpdateLoggingMixin);
485
481 - let root = <App />;
482 - root = ReactTestUtils.renderIntoDocument(root);
486 + const container = document.createElement('div');
487 + const root = ReactDOM.render(<App />, container);
488
489 function expectUpdates(desiredWillUpdates, desiredDidUpdates) {
490 let i;
@@ -581,7 +586,8 @@ describe('ReactLegacyUpdates', () => {
586 }
587 }
588
584 - const a = ReactTestUtils.renderIntoDocument(<A />);
589 + const container = document.createElement('div');
590 + const a = ReactDOM.render(<A />, container);
591 ReactDOM.unstable_batchedUpdates(function () {
592 a.setState({x: 1});
593 b.setState({x: 1});
@@ -630,7 +636,8 @@ describe('ReactLegacyUpdates', () => {
636 }
637 }
638
633 - const instance = ReactTestUtils.renderIntoDocument(<Outer />);
639 + const container = document.createElement('div');
640 + const instance = ReactDOM.render(<Outer />, container);
641
642 updates.push('Outer-setState-1');
643 instance.setState({x: 1}, function () {
@@ -698,7 +705,8 @@ describe('ReactLegacyUpdates', () => {
705 }
706 }
707
701 - ReactTestUtils.renderIntoDocument(<MockComponent depth={0} count={2} />);
708 + const container = document.createElement('div');
709 + ReactDOM.render(<MockComponent depth={0} count={2} />, container);
710
711 expect(updates).toEqual([0, 1, 2]);
712
@@ -758,8 +766,10 @@ describe('ReactLegacyUpdates', () => {
766 }
767 }
768
761 - const x = ReactTestUtils.renderIntoDocument(<X />);
762 - const y = ReactTestUtils.renderIntoDocument(<Y />);
769 + let container = document.createElement('div');
770 + const x = ReactDOM.render(<X />, container);
771 + container = document.createElement('div');
772 + const y = ReactDOM.render(<Y />, container);
773 expect(ReactDOM.findDOMNode(x).textContent).toBe('0');
774
775 y.forceUpdate();
@@ -794,11 +804,14 @@ describe('ReactLegacyUpdates', () => {
804 }
805
806 ReactDOM.unstable_batchedUpdates(function () {
797 - ReactTestUtils.renderIntoDocument(
807 + const container = document.createElement('div');
808 +
809 + ReactDOM.render(
810 <div>
811 <A />
812 <B />
813 </div>,
814 + container,
815 );
816 });
817
@@ -859,7 +872,8 @@ describe('ReactLegacyUpdates', () => {
872 }
873 }
874
862 - const component = ReactTestUtils.renderIntoDocument(<A />);
875 + const container = document.createElement('div');
876 + const component = ReactDOM.render(<A />, container);
877
878 ReactDOM.unstable_batchedUpdates(function () {
879 // B will have scheduled an update but the batching should ensure that its
@@ -886,7 +900,8 @@ describe('ReactLegacyUpdates', () => {
900 }
901 }
902
889 - let component = ReactTestUtils.renderIntoDocument(<A />);
903 + let container = document.createElement('div');
904 + let component = ReactDOM.render(<A />, container);
905
906 expect(() => {
907 expect(() => component.setState({}, 'no')).toErrorDev(
@@ -897,7 +912,8 @@ describe('ReactLegacyUpdates', () => {
912 'Invalid argument passed as callback. Expected a function. Instead ' +
913 'received: no',
914 );
900 - component = ReactTestUtils.renderIntoDocument(<A />);
915 + container = document.createElement('div');
916 + component = ReactDOM.render(<A />, container);
917 expect(() => {
918 expect(() => component.setState({}, {foo: 'bar'})).toErrorDev(
919 'Expected the last optional `callback` argument to be ' +
@@ -908,7 +924,8 @@ describe('ReactLegacyUpdates', () => {
924 'received: [object Object]',
925 );
926 // Make sure the warning is deduplicated and doesn't fire again
911 - component = ReactTestUtils.renderIntoDocument(<A />);
927 + container = document.createElement('div');
928 + component = ReactDOM.render(<A />, container);
929 expect(() => component.setState({}, new Foo())).toThrowError(
930 'Invalid argument passed as callback. Expected a function. Instead ' +
931 'received: [object Object]',
@@ -930,7 +947,8 @@ describe('ReactLegacyUpdates', () => {
947 }
948 }
949
933 - let component = ReactTestUtils.renderIntoDocument(<A />);
950 + let container = document.createElement('div');
951 + let component = ReactDOM.render(<A />, container);
952
953 expect(() => {
954 expect(() => component.forceUpdate('no')).toErrorDev(
@@ -941,7 +959,8 @@ describe('ReactLegacyUpdates', () => {
959 'Invalid argument passed as callback. Expected a function. Instead ' +
960 'received: no',
961 );
944 - component = ReactTestUtils.renderIntoDocument(<A />);
962 + container = document.createElement('div');
963 + component = ReactDOM.render(<A />, container);
964 expect(() => {
965 expect(() => component.forceUpdate({foo: 'bar'})).toErrorDev(
966 'Expected the last optional `callback` argument to be ' +
@@ -952,7 +971,8 @@ describe('ReactLegacyUpdates', () => {
971 'received: [object Object]',
972 );
973 // Make sure the warning is deduplicated and doesn't fire again
955 - component = ReactTestUtils.renderIntoDocument(<A />);
974 + container = document.createElement('div');
975 + component = ReactDOM.render(<A />, container);
976 expect(() => component.forceUpdate(new Foo())).toThrowError(
977 'Invalid argument passed as callback. Expected a function. Instead ' +
978 'received: [object Object]',
@@ -1004,7 +1024,8 @@ describe('ReactLegacyUpdates', () => {
1024 }
1025 }
1026
1007 - const parent = ReactTestUtils.renderIntoDocument(<Parent />);
1027 + const container = document.createElement('div');
1028 + const parent = ReactDOM.render(<Parent />, container);
1029 const child = parent.getChild();
1030 ReactDOM.unstable_batchedUpdates(function () {
1031 parent.forceUpdate();