12
12
let React ;
13
13
let ReactDOM ;
14
14
let ReactDOMClient ;
15
- let ReactTestUtils ;
16
15
let JSXRuntime ;
17
16
let JSXDEVRuntime ;
18
17
let act ;
@@ -29,7 +28,6 @@ describe('ReactJSXRuntime', () => {
29
28
JSXDEVRuntime = require ( 'react/jsx-dev-runtime' ) ;
30
29
ReactDOM = require ( 'react-dom' ) ;
31
30
ReactDOMClient = require ( 'react-dom/client' ) ;
32
- ReactTestUtils = require ( 'react-dom/test-utils' ) ;
33
31
act = require ( 'internal-test-utils' ) . act ;
34
32
} ) ;
35
33
@@ -72,26 +70,41 @@ describe('ReactJSXRuntime', () => {
72
70
expect ( container . firstChild . textContent ) . toBe ( 'persimmon' ) ;
73
71
} ) ;
74
72
75
- it ( 'should normalize props with default values' , ( ) => {
73
+ it ( 'should normalize props with default values' , async ( ) => {
76
74
class Component extends React . Component {
77
75
render ( ) {
78
76
return JSXRuntime . jsx ( 'span' , { children : this . props . prop } ) ;
79
77
}
80
78
}
81
79
Component . defaultProps = { prop : 'testKey' } ;
82
80
83
- const instance = ReactTestUtils . renderIntoDocument (
84
- JSXRuntime . jsx ( Component , { } ) ,
85
- ) ;
81
+ let container = document . createElement ( 'div' ) ;
82
+ let root = ReactDOMClient . createRoot ( container ) ;
83
+ let instance ;
84
+ await act ( ( ) => {
85
+ root . render (
86
+ JSXRuntime . jsx ( Component , { ref : current => ( instance = current ) } ) ,
87
+ ) ;
88
+ } ) ;
89
+
86
90
expect ( instance . props . prop ) . toBe ( 'testKey' ) ;
87
91
88
- const inst2 = ReactTestUtils . renderIntoDocument (
89
- JSXRuntime . jsx ( Component , { prop : null } ) ,
90
- ) ;
92
+ container = document . createElement ( 'div' ) ;
93
+ root = ReactDOMClient . createRoot ( container ) ;
94
+ let inst2 ;
95
+ await act ( ( ) => {
96
+ root . render (
97
+ JSXRuntime . jsx ( Component , {
98
+ prop : null ,
99
+ ref : current => ( inst2 = current ) ,
100
+ } ) ,
101
+ ) ;
102
+ } ) ;
103
+
91
104
expect ( inst2 . props . prop ) . toBe ( null ) ;
92
105
} ) ;
93
106
94
- it ( 'throws when changing a prop (in dev) after element creation' , ( ) => {
107
+ it ( 'throws when changing a prop (in dev) after element creation' , async ( ) => {
95
108
class Outer extends React . Component {
96
109
render ( ) {
97
110
const el = JSXRuntime . jsx ( 'div' , { className : 'moo' } ) ;
@@ -109,9 +122,13 @@ describe('ReactJSXRuntime', () => {
109
122
return el ;
110
123
}
111
124
}
112
- const outer = ReactTestUtils . renderIntoDocument (
113
- JSXRuntime . jsx ( Outer , { color : 'orange' } ) ,
114
- ) ;
125
+ const container = document . createElement ( 'div' ) ;
126
+ const root = ReactDOMClient . createRoot ( container ) ;
127
+ await act ( ( ) => {
128
+ root . render ( JSXRuntime . jsx ( Outer , { color : 'orange' } ) ) ;
129
+ } ) ;
130
+
131
+ const outer = container . firstChild ;
115
132
if ( __DEV__ ) {
116
133
expect ( ReactDOM . findDOMNode ( outer ) . className ) . toBe ( 'moo' ) ;
117
134
} else {
@@ -151,15 +168,24 @@ describe('ReactJSXRuntime', () => {
151
168
}
152
169
} ) ;
153
170
154
- it ( 'does not warn for NaN props' , ( ) => {
171
+ it ( 'does not warn for NaN props' , async ( ) => {
155
172
class Test extends React . Component {
156
173
render ( ) {
157
174
return JSXRuntime . jsx ( 'div' , { } ) ;
158
175
}
159
176
}
160
- const test = ReactTestUtils . renderIntoDocument (
161
- JSXRuntime . jsx ( Test , { value : + undefined } ) ,
162
- ) ;
177
+ const container = document . createElement ( 'div' ) ;
178
+ const root = ReactDOMClient . createRoot ( container ) ;
179
+ let test ;
180
+ await act ( ( ) => {
181
+ root . render (
182
+ JSXRuntime . jsx ( Test , {
183
+ value : + undefined ,
184
+ ref : current => ( test = current ) ,
185
+ } ) ,
186
+ ) ;
187
+ } ) ;
188
+
163
189
expect ( test . props . value ) . toBeNaN ( ) ;
164
190
} ) ;
165
191
0 commit comments