Skip to content

Commit 830dc01

Browse files
eps1longaearon
authored andcommitted
Convert ReactChildren to createRoot (#28191)
1 parent 5424130 commit 830dc01

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

packages/react/src/__tests__/ReactChildren-test.js

+26-12
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
describe('ReactChildren', () => {
1313
let React;
14-
let ReactTestUtils;
14+
let ReactDOMClient;
15+
let act;
1516

1617
beforeEach(() => {
1718
jest.resetModules();
1819
React = require('react');
19-
ReactTestUtils = require('react-dom/test-utils');
20+
ReactDOMClient = require('react-dom/client');
21+
act = require('internal-test-utils').act;
2022
});
2123

2224
it('should support identity for simple', () => {
@@ -962,37 +964,49 @@ describe('ReactChildren', () => {
962964
});
963965

964966
describe('with fragments enabled', () => {
965-
it('warns for keys for arrays of elements in a fragment', () => {
967+
it('warns for keys for arrays of elements in a fragment', async () => {
966968
class ComponentReturningArray extends React.Component {
967969
render() {
968970
return [<div />, <div />];
969971
}
970972
}
971973

972-
expect(() =>
973-
ReactTestUtils.renderIntoDocument(<ComponentReturningArray />),
974-
).toErrorDev(
974+
const container = document.createElement('div');
975+
const root = ReactDOMClient.createRoot(container);
976+
await expect(async () => {
977+
await act(() => {
978+
root.render(<ComponentReturningArray />);
979+
});
980+
}).toErrorDev(
975981
'Warning: ' +
976982
'Each child in a list should have a unique "key" prop.' +
977983
' See https://reactjs.org/link/warning-keys for more information.' +
978984
'\n in ComponentReturningArray (at **)',
979985
);
980986
});
981987

982-
it('does not warn when there are keys on elements in a fragment', () => {
988+
it('does not warn when there are keys on elements in a fragment', async () => {
983989
class ComponentReturningArray extends React.Component {
984990
render() {
985991
return [<div key="foo" />, <div key="bar" />];
986992
}
987993
}
988994

989-
ReactTestUtils.renderIntoDocument(<ComponentReturningArray />);
995+
const container = document.createElement('div');
996+
const root = ReactDOMClient.createRoot(container);
997+
await act(() => {
998+
root.render(<ComponentReturningArray />);
999+
});
9901000
});
9911001

992-
it('warns for keys for arrays at the top level', () => {
993-
expect(() =>
994-
ReactTestUtils.renderIntoDocument([<div />, <div />]),
995-
).toErrorDev(
1002+
it('warns for keys for arrays at the top level', async () => {
1003+
const container = document.createElement('div');
1004+
const root = ReactDOMClient.createRoot(container);
1005+
await expect(async () => {
1006+
await act(() => {
1007+
root.render([<div />, <div />]);
1008+
});
1009+
}).toErrorDev(
9961010
'Warning: ' +
9971011
'Each child in a list should have a unique "key" prop.' +
9981012
' See https://reactjs.org/link/warning-keys for more information.',

0 commit comments

Comments
 (0)