Skip to content

Commit 7dacdc1

Browse files
jackpopeJack Pope
authored andcommitted
Clean up legacy render from ReactTestUtilsAct-test (#28091)
Co-authored-by: Jack Pope <[email protected]>
1 parent 5d80b95 commit 7dacdc1

File tree

1 file changed

+33
-84
lines changed

1 file changed

+33
-84
lines changed

packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js

Lines changed: 33 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
let React;
11-
let ReactDOM;
1211
let ReactDOMClient;
1312
let ReactTestUtils;
1413
let Scheduler;
@@ -33,91 +32,57 @@ describe('ReactTestUtils.act()', () => {
3332
jest.restoreAllMocks();
3433
});
3534

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;
6051
}
52+
});
53+
} else {
54+
if (root !== null) {
55+
root.unmount();
56+
root = null;
6157
}
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+
};
8860

89-
function rerenderLegacy(el) {
90-
ReactDOM.render(el, legacyDom);
91-
}
61+
const rerenderConcurrent = el => {
62+
act(() => root.render(el));
63+
};
9264

93-
runActTests('legacy mode', renderLegacy, unmountLegacy, rerenderLegacy);
65+
runActTests(renderConcurrent, unmountConcurrent, rerenderConcurrent);
9466

9567
describe('unacted effects', () => {
9668
function App() {
9769
React.useEffect(() => {}, []);
9870
return null;
9971
}
10072

101-
it('does not warn in legacy mode', () => {
102-
expect(() => {
103-
ReactDOM.render(<App />, document.createElement('div'));
104-
}).toErrorDev([]);
105-
});
106-
10773
// @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'));
11076
act(() => root.render(<App />));
11177
});
11278
});
11379
});
11480

115-
function runActTests(label, render, unmount, rerender) {
116-
describe(label, () => {
81+
function runActTests(render, unmount, rerender) {
82+
describe('concurrent render', () => {
11783
beforeEach(() => {
11884
jest.resetModules();
11985
React = require('react');
120-
ReactDOM = require('react-dom');
12186
ReactDOMClient = require('react-dom/client');
12287
ReactTestUtils = require('react-dom/test-utils');
12388
Scheduler = require('scheduler');
@@ -703,14 +668,6 @@ function runActTests(label, render, unmount, rerender) {
703668

704669
// @gate __DEV__
705670
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-
714671
let resolved = false;
715672
let resolve;
716673
const promise = new Promise(_resolve => {
@@ -759,16 +716,8 @@ function runActTests(label, render, unmount, rerender) {
759716
});
760717
});
761718

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();
772721

773722
// resolve the promise
774723
await act(async () => {

0 commit comments

Comments
 (0)