10
10
'use strict' ;
11
11
12
12
const React = require ( 'react' ) ;
13
- const ReactDOM = require ( 'react-dom' ) ;
13
+ const ReactDOMClient = require ( 'react-dom/client ' ) ;
14
14
const ReactDOMServer = require ( 'react-dom/server' ) ;
15
+ const act = require ( 'internal-test-utils' ) . act ;
15
16
16
17
describe ( 'CSSPropertyOperations' , ( ) => {
17
18
it ( 'should automatically append `px` to relevant styles' , ( ) => {
@@ -66,15 +67,19 @@ describe('CSSPropertyOperations', () => {
66
67
expect ( html ) . toContain ( '"--someColor:#000000"' ) ;
67
68
} ) ;
68
69
69
- it ( 'should set style attribute when styles exist' , ( ) => {
70
+ it ( 'should set style attribute when styles exist' , async ( ) => {
70
71
const styles = {
71
72
backgroundColor : '#000' ,
72
73
display : 'none' ,
73
74
} ;
74
- let div = < div style = { styles } /> ;
75
- const root = document . createElement ( 'div' ) ;
76
- div = ReactDOM . render ( div , root ) ;
77
- expect ( / s t y l e = " .* " / . test ( root . innerHTML ) ) . toBe ( true ) ;
75
+ const container = document . createElement ( 'div' ) ;
76
+ const root = ReactDOMClient . createRoot ( container ) ;
77
+ await act ( ( ) => {
78
+ root . render ( < div style = { styles } /> ) ;
79
+ } ) ;
80
+
81
+ const div = container . firstChild ;
82
+ expect ( / s t y l e = " .* " / . test ( container . innerHTML ) ) . toBe ( true ) ;
78
83
} ) ;
79
84
80
85
it ( 'should not set style attribute when no styles exist' , ( ) => {
@@ -87,7 +92,7 @@ describe('CSSPropertyOperations', () => {
87
92
expect ( / s t y l e = / . test ( html ) ) . toBe ( false ) ;
88
93
} ) ;
89
94
90
- it ( 'should warn when using hyphenated style names' , ( ) => {
95
+ it ( 'should warn when using hyphenated style names' , async ( ) => {
91
96
class Comp extends React . Component {
92
97
static displayName = 'Comp' ;
93
98
@@ -96,16 +101,20 @@ describe('CSSPropertyOperations', () => {
96
101
}
97
102
}
98
103
99
- const root = document . createElement ( 'div' ) ;
100
-
101
- expect ( ( ) => ReactDOM . render ( < Comp /> , root ) ) . toErrorDev (
104
+ const container = document . createElement ( 'div' ) ;
105
+ const root = ReactDOMClient . createRoot ( container ) ;
106
+ await expect ( async ( ) => {
107
+ await act ( ( ) => {
108
+ root . render ( < Comp /> ) ;
109
+ } ) ;
110
+ } ) . toErrorDev (
102
111
'Warning: Unsupported style property background-color. Did you mean backgroundColor?' +
103
112
'\n in div (at **)' +
104
113
'\n in Comp (at **)' ,
105
114
) ;
106
115
} ) ;
107
116
108
- it ( 'should warn when updating hyphenated style names' , ( ) => {
117
+ it ( 'should warn when updating hyphenated style names' , async ( ) => {
109
118
class Comp extends React . Component {
110
119
static displayName = 'Comp' ;
111
120
@@ -118,10 +127,16 @@ describe('CSSPropertyOperations', () => {
118
127
'-ms-transform' : 'translate3d(0, 0, 0)' ,
119
128
'-webkit-transform' : 'translate3d(0, 0, 0)' ,
120
129
} ;
121
- const root = document . createElement ( 'div' ) ;
122
- ReactDOM . render ( < Comp /> , root ) ;
123
-
124
- expect ( ( ) => ReactDOM . render ( < Comp style = { styles } /> , root ) ) . toErrorDev ( [
130
+ const container = document . createElement ( 'div' ) ;
131
+ const root = ReactDOMClient . createRoot ( container ) ;
132
+ await act ( ( ) => {
133
+ root . render ( < Comp /> ) ;
134
+ } ) ;
135
+ await expect ( async ( ) => {
136
+ await act ( ( ) => {
137
+ root . render ( < Comp style = { styles } /> ) ;
138
+ } ) ;
139
+ } ) . toErrorDev ( [
125
140
'Warning: Unsupported style property -ms-transform. Did you mean msTransform?' +
126
141
'\n in div (at **)' +
127
142
'\n in Comp (at **)' ,
@@ -131,7 +146,7 @@ describe('CSSPropertyOperations', () => {
131
146
] ) ;
132
147
} ) ;
133
148
134
- it ( 'warns when miscapitalizing vendored style names' , ( ) => {
149
+ it ( 'warns when miscapitalizing vendored style names' , async ( ) => {
135
150
class Comp extends React . Component {
136
151
static displayName = 'Comp' ;
137
152
@@ -148,9 +163,13 @@ describe('CSSPropertyOperations', () => {
148
163
}
149
164
}
150
165
151
- const root = document . createElement ( 'div' ) ;
152
-
153
- expect ( ( ) => ReactDOM . render ( < Comp /> , root ) ) . toErrorDev ( [
166
+ const container = document . createElement ( 'div' ) ;
167
+ const root = ReactDOMClient . createRoot ( container ) ;
168
+ await expect ( async ( ) => {
169
+ await act ( ( ) => {
170
+ root . render ( < Comp /> ) ;
171
+ } ) ;
172
+ } ) . toErrorDev ( [
154
173
// msTransform is correct already and shouldn't warn
155
174
'Warning: Unsupported vendor-prefixed style property oTransform. ' +
156
175
'Did you mean OTransform?' +
@@ -163,7 +182,7 @@ describe('CSSPropertyOperations', () => {
163
182
] ) ;
164
183
} ) ;
165
184
166
- it ( 'should warn about style having a trailing semicolon' , ( ) => {
185
+ it ( 'should warn about style having a trailing semicolon' , async ( ) => {
167
186
class Comp extends React . Component {
168
187
static displayName = 'Comp' ;
169
188
@@ -181,9 +200,13 @@ describe('CSSPropertyOperations', () => {
181
200
}
182
201
}
183
202
184
- const root = document . createElement ( 'div' ) ;
185
-
186
- expect ( ( ) => ReactDOM . render ( < Comp /> , root ) ) . toErrorDev ( [
203
+ const container = document . createElement ( 'div' ) ;
204
+ const root = ReactDOMClient . createRoot ( container ) ;
205
+ await expect ( async ( ) => {
206
+ await act ( ( ) => {
207
+ root . render ( < Comp /> ) ;
208
+ } ) ;
209
+ } ) . toErrorDev ( [
187
210
"Warning: Style property values shouldn't contain a semicolon. " +
188
211
'Try "backgroundColor: blue" instead.' +
189
212
'\n in div (at **)' +
@@ -195,7 +218,7 @@ describe('CSSPropertyOperations', () => {
195
218
] ) ;
196
219
} ) ;
197
220
198
- it ( 'should warn about style containing a NaN value' , ( ) => {
221
+ it ( 'should warn about style containing a NaN value' , async ( ) => {
199
222
class Comp extends React . Component {
200
223
static displayName = 'Comp' ;
201
224
@@ -204,27 +227,34 @@ describe('CSSPropertyOperations', () => {
204
227
}
205
228
}
206
229
207
- const root = document . createElement ( 'div' ) ;
208
-
209
- expect ( ( ) => ReactDOM . render ( < Comp /> , root ) ) . toErrorDev (
230
+ const container = document . createElement ( 'div' ) ;
231
+ const root = ReactDOMClient . createRoot ( container ) ;
232
+ await expect ( async ( ) => {
233
+ await act ( ( ) => {
234
+ root . render ( < Comp /> ) ;
235
+ } ) ;
236
+ } ) . toErrorDev (
210
237
'Warning: `NaN` is an invalid value for the `fontSize` css style property.' +
211
238
'\n in div (at **)' +
212
239
'\n in Comp (at **)' ,
213
240
) ;
214
241
} ) ;
215
242
216
- it ( 'should not warn when setting CSS custom properties' , ( ) => {
243
+ it ( 'should not warn when setting CSS custom properties' , async ( ) => {
217
244
class Comp extends React . Component {
218
245
render ( ) {
219
246
return < div style = { { '--foo-primary' : 'red' , backgroundColor : 'red' } } /> ;
220
247
}
221
248
}
222
249
223
- const root = document . createElement ( 'div' ) ;
224
- ReactDOM . render ( < Comp /> , root ) ;
250
+ const container = document . createElement ( 'div' ) ;
251
+ const root = ReactDOMClient . createRoot ( container ) ;
252
+ await act ( ( ) => {
253
+ root . render ( < Comp /> ) ;
254
+ } ) ;
225
255
} ) ;
226
256
227
- it ( 'should warn about style containing an Infinity value' , ( ) => {
257
+ it ( 'should warn about style containing an Infinity value' , async ( ) => {
228
258
class Comp extends React . Component {
229
259
static displayName = 'Comp' ;
230
260
@@ -233,25 +263,32 @@ describe('CSSPropertyOperations', () => {
233
263
}
234
264
}
235
265
236
- const root = document . createElement ( 'div' ) ;
237
-
238
- expect ( ( ) => ReactDOM . render ( < Comp /> , root ) ) . toErrorDev (
266
+ const container = document . createElement ( 'div' ) ;
267
+ const root = ReactDOMClient . createRoot ( container ) ;
268
+ await expect ( async ( ) => {
269
+ await act ( ( ) => {
270
+ root . render ( < Comp /> ) ;
271
+ } ) ;
272
+ } ) . toErrorDev (
239
273
'Warning: `Infinity` is an invalid value for the `fontSize` css style property.' +
240
274
'\n in div (at **)' +
241
275
'\n in Comp (at **)' ,
242
276
) ;
243
277
} ) ;
244
278
245
- it ( 'should not add units to CSS custom properties' , ( ) => {
279
+ it ( 'should not add units to CSS custom properties' , async ( ) => {
246
280
class Comp extends React . Component {
247
281
render ( ) {
248
282
return < div style = { { '--foo' : '5' } } /> ;
249
283
}
250
284
}
251
285
252
- const root = document . createElement ( 'div' ) ;
253
- ReactDOM . render ( < Comp /> , root ) ;
286
+ const container = document . createElement ( 'div' ) ;
287
+ const root = ReactDOMClient . createRoot ( container ) ;
288
+ await act ( ( ) => {
289
+ root . render ( < Comp /> ) ;
290
+ } ) ;
254
291
255
- expect ( root . children [ 0 ] . style . getPropertyValue ( '--foo' ) ) . toEqual ( '5' ) ;
292
+ expect ( container . children [ 0 ] . style . getPropertyValue ( '--foo' ) ) . toEqual ( '5' ) ;
256
293
} ) ;
257
294
} ) ;
0 commit comments