|
11 | 11 |
|
12 | 12 | describe('ReactChildren', () => {
|
13 | 13 | let React;
|
14 |
| - let ReactTestUtils; |
| 14 | + let ReactDOMClient; |
| 15 | + let act; |
15 | 16 |
|
16 | 17 | beforeEach(() => {
|
17 | 18 | jest.resetModules();
|
18 | 19 | React = require('react');
|
19 |
| - ReactTestUtils = require('react-dom/test-utils'); |
| 20 | + ReactDOMClient = require('react-dom/client'); |
| 21 | + act = require('internal-test-utils').act; |
20 | 22 | });
|
21 | 23 |
|
22 | 24 | it('should support identity for simple', () => {
|
@@ -962,37 +964,49 @@ describe('ReactChildren', () => {
|
962 | 964 | });
|
963 | 965 |
|
964 | 966 | 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 () => { |
966 | 968 | class ComponentReturningArray extends React.Component {
|
967 | 969 | render() {
|
968 | 970 | return [<div />, <div />];
|
969 | 971 | }
|
970 | 972 | }
|
971 | 973 |
|
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( |
975 | 981 | 'Warning: ' +
|
976 | 982 | 'Each child in a list should have a unique "key" prop.' +
|
977 | 983 | ' See https://reactjs.org/link/warning-keys for more information.' +
|
978 | 984 | '\n in ComponentReturningArray (at **)',
|
979 | 985 | );
|
980 | 986 | });
|
981 | 987 |
|
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 () => { |
983 | 989 | class ComponentReturningArray extends React.Component {
|
984 | 990 | render() {
|
985 | 991 | return [<div key="foo" />, <div key="bar" />];
|
986 | 992 | }
|
987 | 993 | }
|
988 | 994 |
|
989 |
| - ReactTestUtils.renderIntoDocument(<ComponentReturningArray />); |
| 995 | + const container = document.createElement('div'); |
| 996 | + const root = ReactDOMClient.createRoot(container); |
| 997 | + await act(() => { |
| 998 | + root.render(<ComponentReturningArray />); |
| 999 | + }); |
990 | 1000 | });
|
991 | 1001 |
|
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( |
996 | 1010 | 'Warning: ' +
|
997 | 1011 | 'Each child in a list should have a unique "key" prop.' +
|
998 | 1012 | ' See https://reactjs.org/link/warning-keys for more information.',
|
|
0 commit comments