6
6
*
7
7
* @emails react-core
8
8
*/
9
-
10
9
'use strict' ;
11
10
12
11
let React ;
13
- let ReactDOM ;
12
+ let ReactDOMClient ;
14
13
let ReactDOMServer ;
14
+ let act ;
15
15
16
16
describe ( 'ReactDOMSVG' , ( ) => {
17
17
beforeEach ( ( ) => {
18
18
React = require ( 'react' ) ;
19
- ReactDOM = require ( 'react-dom' ) ;
19
+ ReactDOMClient = require ( 'react-dom/client ' ) ;
20
20
ReactDOMServer = require ( 'react-dom/server' ) ;
21
+ act = require ( 'internal-test-utils' ) . act ;
21
22
} ) ;
22
23
23
24
it ( 'creates initial namespaced markup' , ( ) => {
@@ -29,7 +30,7 @@ describe('ReactDOMSVG', () => {
29
30
expect ( markup ) . toContain ( 'xlink:href="http://i.imgur.com/w7GCRPb.png"' ) ;
30
31
} ) ;
31
32
32
- it ( 'creates elements with SVG namespace inside SVG tag during mount' , ( ) => {
33
+ it ( 'creates elements with SVG namespace inside SVG tag during mount' , async ( ) => {
33
34
const node = document . createElement ( 'div' ) ;
34
35
let div ,
35
36
div2 ,
@@ -45,43 +46,45 @@ describe('ReactDOMSVG', () => {
45
46
svg2 ,
46
47
svg3 ,
47
48
svg4 ;
48
- ReactDOM . render (
49
- < div >
50
- < svg ref = { el => ( svg = el ) } >
51
- < g ref = { el => ( g = el ) } strokeWidth = "5" >
52
- < svg ref = { el => ( svg2 = el ) } >
53
- < foreignObject ref = { el => ( foreignObject = el ) } >
54
- < svg ref = { el => ( svg3 = el ) } >
55
- < svg ref = { el => ( svg4 = el ) } />
56
- < image
57
- ref = { el => ( image = el ) }
58
- xlinkHref = "http://i.imgur.com/w7GCRPb.png"
59
- />
60
- </ svg >
61
- < div ref = { el => ( div = el ) } />
49
+ const root = ReactDOMClient . createRoot ( node ) ;
50
+ await act ( ( ) => {
51
+ root . render (
52
+ < div >
53
+ < svg ref = { el => ( svg = el ) } >
54
+ < g ref = { el => ( g = el ) } strokeWidth = "5" >
55
+ < svg ref = { el => ( svg2 = el ) } >
56
+ < foreignObject ref = { el => ( foreignObject = el ) } >
57
+ < svg ref = { el => ( svg3 = el ) } >
58
+ < svg ref = { el => ( svg4 = el ) } />
59
+ < image
60
+ ref = { el => ( image = el ) }
61
+ xlinkHref = "http://i.imgur.com/w7GCRPb.png"
62
+ />
63
+ </ svg >
64
+ < div ref = { el => ( div = el ) } />
65
+ </ foreignObject >
66
+ </ svg >
67
+ < image
68
+ ref = { el => ( image2 = el ) }
69
+ xlinkHref = "http://i.imgur.com/w7GCRPb.png"
70
+ />
71
+ < foreignObject ref = { el => ( foreignObject2 = el ) } >
72
+ < div ref = { el => ( div2 = el ) } />
62
73
</ foreignObject >
63
- </ svg >
64
- < image
65
- ref = { el => ( image2 = el ) }
66
- xlinkHref = "http://i.imgur.com/w7GCRPb.png"
67
- />
68
- < foreignObject ref = { el => ( foreignObject2 = el ) } >
69
- < div ref = { el => ( div2 = el ) } />
70
- </ foreignObject >
71
- </ g >
72
- </ svg >
73
- < p ref = { el => ( p = el ) } >
74
- < svg >
75
- < image
76
- ref = { el => ( image3 = el ) }
77
- xlinkHref = "http://i.imgur.com/w7GCRPb.png"
78
- />
74
+ </ g >
79
75
</ svg >
80
- </ p >
81
- < div ref = { el => ( div3 = el ) } />
82
- </ div > ,
83
- node ,
84
- ) ;
76
+ < p ref = { el => ( p = el ) } >
77
+ < svg >
78
+ < image
79
+ ref = { el => ( image3 = el ) }
80
+ xlinkHref = "http://i.imgur.com/w7GCRPb.png"
81
+ />
82
+ </ svg >
83
+ </ p >
84
+ < div ref = { el => ( div3 = el ) } />
85
+ </ div > ,
86
+ ) ;
87
+ } ) ;
85
88
[ svg , svg2 , svg3 , svg4 ] . forEach ( el => {
86
89
expect ( el . namespaceURI ) . toBe ( 'http://www.w3.org/2000/svg' ) ;
87
90
// SVG tagName is case sensitive.
@@ -110,7 +113,7 @@ describe('ReactDOMSVG', () => {
110
113
} ) ;
111
114
} ) ;
112
115
113
- it ( 'creates elements with SVG namespace inside SVG tag during update' , ( ) => {
116
+ it ( 'creates elements with SVG namespace inside SVG tag during update' , async ( ) => {
114
117
let inst ,
115
118
div ,
116
119
div2 ,
@@ -126,6 +129,7 @@ describe('ReactDOMSVG', () => {
126
129
127
130
class App extends React . Component {
128
131
state = { step : 0 } ;
132
+
129
133
render ( ) {
130
134
inst = this ;
131
135
const { step} = this . state ;
@@ -159,15 +163,19 @@ describe('ReactDOMSVG', () => {
159
163
}
160
164
161
165
const node = document . createElement ( 'div' ) ;
162
- ReactDOM . render (
163
- < svg ref = { el => ( svg = el ) } >
164
- < App />
165
- </ svg > ,
166
- node ,
167
- ) ;
168
- inst . setState ( { step : 1 } ) ;
166
+ const root = ReactDOMClient . createRoot ( node ) ;
167
+ await act ( ( ) => {
168
+ root . render (
169
+ < svg ref = { el => ( svg = el ) } >
170
+ < App />
171
+ </ svg > ,
172
+ ) ;
173
+ } ) ;
174
+ await act ( ( ) => {
175
+ inst . setState ( { step : 1 } ) ;
176
+ } ) ;
169
177
170
- [ svg , svg2 , svg3 , svg4 ] . forEach ( el => {
178
+ [ ( svg , svg2 , svg3 , svg4 ) ] . forEach ( el => {
171
179
expect ( el . namespaceURI ) . toBe ( 'http://www.w3.org/2000/svg' ) ;
172
180
// SVG tagName is case sensitive.
173
181
expect ( el . tagName ) . toBe ( 'svg' ) ;
@@ -193,7 +201,7 @@ describe('ReactDOMSVG', () => {
193
201
} ) ;
194
202
} ) ;
195
203
196
- it ( 'can render SVG into a non-React SVG tree' , ( ) => {
204
+ it ( 'can render SVG into a non-React SVG tree' , async ( ) => {
197
205
const outerSVGRoot = document . createElementNS (
198
206
'http://www.w3.org/2000/svg' ,
199
207
'svg' ,
@@ -204,12 +212,15 @@ describe('ReactDOMSVG', () => {
204
212
) ;
205
213
outerSVGRoot . appendChild ( container ) ;
206
214
let image ;
207
- ReactDOM . render ( < image ref = { el => ( image = el ) } /> , container ) ;
215
+ const root = ReactDOMClient . createRoot ( container ) ;
216
+ await act ( ( ) => {
217
+ root . render ( < image ref = { el => ( image = el ) } /> ) ;
218
+ } ) ;
208
219
expect ( image . namespaceURI ) . toBe ( 'http://www.w3.org/2000/svg' ) ;
209
220
expect ( image . tagName ) . toBe ( 'image' ) ;
210
221
} ) ;
211
222
212
- it ( 'can render HTML into a foreignObject in non-React SVG tree' , ( ) => {
223
+ it ( 'can render HTML into a foreignObject in non-React SVG tree' , async ( ) => {
213
224
const outerSVGRoot = document . createElementNS (
214
225
'http://www.w3.org/2000/svg' ,
215
226
'svg' ,
@@ -220,7 +231,10 @@ describe('ReactDOMSVG', () => {
220
231
) ;
221
232
outerSVGRoot . appendChild ( container ) ;
222
233
let div ;
223
- ReactDOM . render ( < div ref = { el => ( div = el ) } /> , container ) ;
234
+ const root = ReactDOMClient . createRoot ( container ) ;
235
+ await act ( ( ) => {
236
+ root . render ( < div ref = { el => ( div = el ) } /> ) ;
237
+ } ) ;
224
238
expect ( div . namespaceURI ) . toBe ( 'http://www.w3.org/1999/xhtml' ) ;
225
239
expect ( div . tagName ) . toBe ( 'DIV' ) ;
226
240
} ) ;
0 commit comments