1313'use strict' ;
1414
1515let React ;
16- let ReactTestUtils ;
16+ let ReactDOMClient ;
17+ let act ;
1718
1819describe ( 'ReactChildReconciler' , ( ) => {
1920 beforeEach ( ( ) => {
2021 jest . resetModules ( ) ;
2122
2223 React = require ( 'react' ) ;
23- ReactTestUtils = require ( 'react-dom/test-utils' ) ;
24+ ReactDOMClient = require ( 'react-dom/client' ) ;
25+ act = require ( 'internal-test-utils' ) . act ;
2426 } ) ;
2527
2628 function createIterable ( array ) {
@@ -55,37 +57,47 @@ describe('ReactChildReconciler', () => {
5557 return fn ;
5658 }
5759
58- it ( 'does not treat functions as iterables' , ( ) => {
59- let node ;
60+ it ( 'does not treat functions as iterables' , async ( ) => {
6061 const iterableFunction = makeIterableFunction ( 'foo' ) ;
6162
62- expect ( ( ) => {
63- node = ReactTestUtils . renderIntoDocument (
64- < div >
65- < h1 > { iterableFunction } </ h1 >
66- </ div > ,
67- ) ;
63+ const container = document . createElement ( 'div' ) ;
64+ const root = ReactDOMClient . createRoot ( container ) ;
65+ await expect ( async ( ) => {
66+ await act ( ( ) => {
67+ root . render (
68+ < div >
69+ < h1 > { iterableFunction } </ h1 >
70+ </ div > ,
71+ ) ;
72+ } ) ;
6873 } ) . toErrorDev ( 'Functions are not valid as a React child' ) ;
74+ const node = container . firstChild ;
6975
7076 expect ( node . innerHTML ) . toContain ( '' ) ; // h1
7177 } ) ;
7278
73- it ( 'warns for duplicated array keys' , ( ) => {
79+ it ( 'warns for duplicated array keys' , async ( ) => {
7480 class Component extends React . Component {
7581 render ( ) {
7682 return < div > { [ < div key = "1" /> , < div key = "1" /> ] } </ div > ;
7783 }
7884 }
7985
80- expect ( ( ) => ReactTestUtils . renderIntoDocument ( < Component /> ) ) . toErrorDev (
86+ const container = document . createElement ( 'div' ) ;
87+ const root = ReactDOMClient . createRoot ( container ) ;
88+ await expect ( async ( ) => {
89+ await act ( ( ) => {
90+ root . render ( < Component /> ) ;
91+ } ) ;
92+ } ) . toErrorDev (
8193 'Keys should be unique so that components maintain their identity ' +
8294 'across updates. Non-unique keys may cause children to be ' +
8395 'duplicated and/or omitted — the behavior is unsupported and ' +
8496 'could change in a future version.' ,
8597 ) ;
8698 } ) ;
8799
88- it ( 'warns for duplicated array keys with component stack info' , ( ) => {
100+ it ( 'warns for duplicated array keys with component stack info' , async ( ) => {
89101 class Component extends React . Component {
90102 render ( ) {
91103 return < div > { [ < div key = "1" /> , < div key = "1" /> ] } </ div > ;
@@ -104,7 +116,13 @@ describe('ReactChildReconciler', () => {
104116 }
105117 }
106118
107- expect ( ( ) => ReactTestUtils . renderIntoDocument ( < GrandParent /> ) ) . toErrorDev (
119+ const container = document . createElement ( 'div' ) ;
120+ const root = ReactDOMClient . createRoot ( container ) ;
121+ await expect ( async ( ) => {
122+ await act ( ( ) => {
123+ root . render ( < GrandParent /> ) ;
124+ } ) ;
125+ } ) . toErrorDev (
108126 'Encountered two children with the same key, `1`. ' +
109127 'Keys should be unique so that components maintain their identity ' +
110128 'across updates. Non-unique keys may cause children to be ' +
@@ -117,22 +135,28 @@ describe('ReactChildReconciler', () => {
117135 ) ;
118136 } ) ;
119137
120- it ( 'warns for duplicated iterable keys' , ( ) => {
138+ it ( 'warns for duplicated iterable keys' , async ( ) => {
121139 class Component extends React . Component {
122140 render ( ) {
123141 return < div > { createIterable ( [ < div key = "1" /> , < div key = "1" /> ] ) } </ div > ;
124142 }
125143 }
126144
127- expect ( ( ) => ReactTestUtils . renderIntoDocument ( < Component /> ) ) . toErrorDev (
145+ const container = document . createElement ( 'div' ) ;
146+ const root = ReactDOMClient . createRoot ( container ) ;
147+ await expect ( async ( ) => {
148+ await act ( ( ) => {
149+ root . render ( < Component /> ) ;
150+ } ) ;
151+ } ) . toErrorDev (
128152 'Keys should be unique so that components maintain their identity ' +
129153 'across updates. Non-unique keys may cause children to be ' +
130154 'duplicated and/or omitted — the behavior is unsupported and ' +
131155 'could change in a future version.' ,
132156 ) ;
133157 } ) ;
134158
135- it ( 'warns for duplicated iterable keys with component stack info' , ( ) => {
159+ it ( 'warns for duplicated iterable keys with component stack info' , async ( ) => {
136160 class Component extends React . Component {
137161 render ( ) {
138162 return < div > { createIterable ( [ < div key = "1" /> , < div key = "1" /> ] ) } </ div > ;
@@ -151,7 +175,13 @@ describe('ReactChildReconciler', () => {
151175 }
152176 }
153177
154- expect ( ( ) => ReactTestUtils . renderIntoDocument ( < GrandParent /> ) ) . toErrorDev (
178+ const container = document . createElement ( 'div' ) ;
179+ const root = ReactDOMClient . createRoot ( container ) ;
180+ await expect ( async ( ) => {
181+ await act ( ( ) => {
182+ root . render ( < GrandParent /> ) ;
183+ } ) ;
184+ } ) . toErrorDev (
155185 'Encountered two children with the same key, `1`. ' +
156186 'Keys should be unique so that components maintain their identity ' +
157187 'across updates. Non-unique keys may cause children to be ' +
0 commit comments