Clean up legacy render from ReactTestUtilsAct-test (#28091)
Co-authored-by: Jack Pope <jackpope@meta.com>
Jack Pope committed
Jan 26, 2024 at 19:29 UTC
91212b09ed53c8d5a0f414ed93972681caa5ac7e
1 file changed
+33
-84
packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js
+33
-84
@@ -8,7 +8,6 @@
8
*/
9
10
let React;
11
-let ReactDOM;
11
let ReactDOMClient;
12
let ReactTestUtils;
13
let Scheduler;
@@ -33,64 +32,37 @@ describe('ReactTestUtils.act()', () => {
32
jest.restoreAllMocks();
33
});
34
36
- // first we run all the tests with concurrent mode
37
- if (__EXPERIMENTAL__) {
38
- let concurrentRoot = null;
39
- const renderConcurrent = (el, dom) => {
40
- concurrentRoot = ReactDOMClient.createRoot(dom);
41
- if (__DEV__) {
42
- act(() => concurrentRoot.render(el));
43
- } else {
44
- concurrentRoot.render(el);
45
- }
46
- };
47
-
48
- const unmountConcurrent = _dom => {
49
- if (__DEV__) {
50
- act(() => {
51
- if (concurrentRoot !== null) {
52
- concurrentRoot.unmount();
53
- concurrentRoot = null;
54
- }
55
- });
56
- } else {
57
- if (concurrentRoot !== null) {
58
- concurrentRoot.unmount();
59
- concurrentRoot = null;
35
+ let root = null;
36
+ const renderConcurrent = (el, dom) => {
37
+ root = ReactDOMClient.createRoot(dom);
38
+ if (__DEV__) {
39
+ act(() => root.render(el));
40
+ } else {
41
+ root.render(el);
42
+ }
43
+ };
44
+
45
+ const unmountConcurrent = _dom => {
46
+ if (__DEV__) {
47
+ act(() => {
48
+ if (root !== null) {
49
+ root.unmount();
50
+ root = null;
51
}
52
+ });
53
+ } else {
54
+ if (root !== null) {
55
+ root.unmount();
56
+ root = null;
57
}
62
- };
63
-
64
- const rerenderConcurrent = el => {
65
- act(() => concurrentRoot.render(el));
66
- };
67
-
68
- runActTests(
69
- 'concurrent mode',
70
- renderConcurrent,
71
- unmountConcurrent,
72
- rerenderConcurrent,
73
- );
74
- }
75
-
76
- // and then in legacy mode
77
-
78
- let legacyDom = null;
79
- function renderLegacy(el, dom) {
80
- legacyDom = dom;
81
- ReactDOM.render(el, dom);
82
- }
83
-
84
- function unmountLegacy(dom) {
85
- legacyDom = null;
86
- ReactDOM.unmountComponentAtNode(dom);
87
- }
58
+ }
59
+ };
60
89
- function rerenderLegacy(el) {
90
- ReactDOM.render(el, legacyDom);
91
- }
61
+ const rerenderConcurrent = el => {
62
+ act(() => root.render(el));
63
+ };
64
93
- runActTests('legacy mode', renderLegacy, unmountLegacy, rerenderLegacy);
65
+ runActTests(renderConcurrent, unmountConcurrent, rerenderConcurrent);
66
67
describe('unacted effects', () => {
68
function App() {
@@ -98,26 +70,19 @@ describe('ReactTestUtils.act()', () => {
70
return null;
71
}
72
101
- it('does not warn in legacy mode', () => {
102
- expect(() => {
103
- ReactDOM.render(<App />, document.createElement('div'));
104
- }).toErrorDev([]);
105
- });
106
-
73
// @gate __DEV__
108
- it('does not warn in concurrent mode', () => {
109
- const root = ReactDOMClient.createRoot(document.createElement('div'));
74
+ it('does not warn', () => {
75
+ root = ReactDOMClient.createRoot(document.createElement('div'));
76
act(() => root.render(<App />));
77
});
78
});
79
});
80
115
-function runActTests(label, render, unmount, rerender) {
116
- describe(label, () => {
81
+function runActTests(render, unmount, rerender) {
82
+ describe('concurrent render', () => {
83
beforeEach(() => {
84
jest.resetModules();
85
React = require('react');
120
- ReactDOM = require('react-dom');
86
ReactDOMClient = require('react-dom/client');
87
ReactTestUtils = require('react-dom/test-utils');
88
Scheduler = require('scheduler');
@@ -703,14 +668,6 @@ function runActTests(label, render, unmount, rerender) {
668
669
// @gate __DEV__
670
it('triggers fallbacks if available', async () => {
706
- if (label !== 'legacy mode') {
707
- // FIXME: Support for Concurrent Root intentionally removed
708
- // from the public version of `act`. It will be added back in
709
- // a future major version, before the Concurrent Root is released.
710
- // Consider skipping all non-Legacy tests in this suite until then.
711
- return;
712
- }
713
-
671
let resolved = false;
672
let resolve;
673
const promise = new Promise(_resolve => {
@@ -759,16 +716,8 @@ function runActTests(label, render, unmount, rerender) {
716
});
717
});
718
762
- if (label === 'concurrent mode') {
763
- // In Concurrent Mode, refresh transitions delay indefinitely.
764
- expect(document.querySelector('[data-test-id=spinner]')).toBeNull();
765
- } else {
766
- // In Legacy Mode, all fallbacks are forced to display,
767
- // even during a refresh transition.
768
- expect(
769
- document.querySelector('[data-test-id=spinner]'),
770
- ).not.toBeNull();
771
- }
719
+ // In Concurrent Mode, refresh transitions delay indefinitely.
720
+ expect(document.querySelector('[data-test-id=spinner]')).toBeNull();
721
722
// resolve the promise
723
await act(async () => {