@@ -13,7 +13,6 @@ let act;
13
13
14
14
let React ;
15
15
let ReactDOMClient ;
16
- let ReactTestUtils ;
17
16
18
17
describe ( 'ReactElement' , ( ) => {
19
18
let ComponentClass ;
@@ -25,7 +24,6 @@ describe('ReactElement', () => {
25
24
26
25
React = require ( 'react' ) ;
27
26
ReactDOMClient = require ( 'react-dom/client' ) ;
28
- ReactTestUtils = require ( 'react-dom/test-utils' ) ;
29
27
// NOTE: We're explicitly not using JSX here. This is intended to test
30
28
// classic JS without JSX.
31
29
ComponentClass = class extends React . Component {
@@ -223,19 +221,21 @@ describe('ReactElement', () => {
223
221
expect ( element . props ) . toEqual ( { foo : '56' } ) ;
224
222
} ) ;
225
223
226
- it ( 'preserves the owner on the element' , ( ) => {
224
+ it ( 'preserves the owner on the element' , async ( ) => {
227
225
let element ;
226
+ let instance ;
228
227
229
228
class Wrapper extends React . Component {
229
+ componentDidMount ( ) {
230
+ instance = this ;
231
+ }
230
232
render ( ) {
231
233
element = React . createElement ( ComponentClass ) ;
232
234
return element ;
233
235
}
234
236
}
235
-
236
- const instance = ReactTestUtils . renderIntoDocument (
237
- React . createElement ( Wrapper ) ,
238
- ) ;
237
+ const root = ReactDOMClient . createRoot ( document . createElement ( 'div' ) ) ;
238
+ await act ( ( ) => root . render ( React . createElement ( Wrapper ) ) ) ;
239
239
expect ( element . _owner . stateNode ) . toBe ( instance ) ;
240
240
} ) ;
241
241
@@ -327,23 +327,28 @@ describe('ReactElement', () => {
327
327
328
328
// NOTE: We're explicitly not using JSX here. This is intended to test
329
329
// classic JS without JSX.
330
- it ( 'should normalize props with default values' , ( ) => {
330
+ it ( 'should normalize props with default values' , async ( ) => {
331
+ let instance ;
331
332
class Component extends React . Component {
333
+ componentDidMount ( ) {
334
+ instance = this ;
335
+ }
332
336
render ( ) {
333
337
return React . createElement ( 'span' , null , this . props . prop ) ;
334
338
}
335
339
}
336
340
Component . defaultProps = { prop : 'testKey' } ;
337
341
338
- const instance = ReactTestUtils . renderIntoDocument (
339
- React . createElement ( Component ) ,
340
- ) ;
342
+ const root = ReactDOMClient . createRoot ( document . createElement ( 'div' ) ) ;
343
+ await act ( ( ) => {
344
+ root . render ( React . createElement ( Component ) ) ;
345
+ } ) ;
341
346
expect ( instance . props . prop ) . toBe ( 'testKey' ) ;
342
347
343
- const inst2 = ReactTestUtils . renderIntoDocument (
344
- React . createElement ( Component , { prop : null } ) ,
345
- ) ;
346
- expect ( inst2 . props . prop ) . toBe ( null ) ;
348
+ await act ( ( ) => {
349
+ root . render ( React . createElement ( Component , { prop : null } ) ) ;
350
+ } ) ;
351
+ expect ( instance . props . prop ) . toBe ( null ) ;
347
352
} ) ;
348
353
349
354
it ( 'throws when changing a prop (in dev) after element creation' , async ( ) => {
@@ -410,13 +415,20 @@ describe('ReactElement', () => {
410
415
}
411
416
} ) ;
412
417
413
- it ( 'does not warn for NaN props' , ( ) => {
418
+ it ( 'does not warn for NaN props' , async ( ) => {
419
+ let test ;
414
420
class Test extends React . Component {
421
+ componentDidMount ( ) {
422
+ test = this ;
423
+ }
415
424
render ( ) {
416
425
return < div /> ;
417
426
}
418
427
}
419
- const test = ReactTestUtils . renderIntoDocument ( < Test value = { + undefined } /> ) ;
428
+ const root = ReactDOMClient . createRoot ( document . createElement ( 'div' ) ) ;
429
+ await act ( ( ) => {
430
+ root . render ( < Test value = { + undefined } /> ) ;
431
+ } ) ;
420
432
expect ( test . props . value ) . toBeNaN ( ) ;
421
433
} ) ;
422
434
} ) ;
0 commit comments