1
1
import React from "react" ;
2
2
import ReactDOM from "react-dom" ;
3
- import ReactDOMServer from "react-dom/server" ;
4
3
import createHistory from "history/createMemoryHistory" ;
5
4
6
5
import { Router , StaticRouter } from "react-router" ;
7
6
import { renderRoutes } from "react-router-config" ;
8
7
8
+ import renderStrict from "./utils/renderStrict" ;
9
+ import renderToStringStrict from "./utils/renderToStringStrict" ;
10
+
9
11
describe ( "renderRoutes" , ( ) => {
10
12
let renderedRoutes ;
11
13
let renderedExtraProps ;
@@ -26,7 +28,7 @@ describe("renderRoutes", () => {
26
28
} ;
27
29
const routes = [ routeToMatch ] ;
28
30
29
- ReactDOMServer . renderToString (
31
+ renderToStringStrict (
30
32
< StaticRouter location = "/path" context = { { } } >
31
33
{ renderRoutes ( routes ) }
32
34
</ StaticRouter >
@@ -42,7 +44,7 @@ describe("renderRoutes", () => {
42
44
const routes = [ routeToMatch ] ;
43
45
const extraProps = { anExtraProp : "anExtraPropValue" } ;
44
46
45
- ReactDOMServer . renderToString (
47
+ renderToStringStrict (
46
48
< StaticRouter location = "/path" context = { { } } >
47
49
{ renderRoutes ( routes , extraProps ) }
48
50
</ StaticRouter >
@@ -64,7 +66,7 @@ describe("renderRoutes", () => {
64
66
] ;
65
67
const extraProps = { anExtraProp : "anExtraPropValue" } ;
66
68
67
- ReactDOMServer . renderToString (
69
+ renderToStringStrict (
68
70
< StaticRouter location = "/" context = { { } } >
69
71
{ renderRoutes ( routes , extraProps ) }
70
72
</ StaticRouter >
@@ -86,7 +88,7 @@ describe("renderRoutes", () => {
86
88
}
87
89
] ;
88
90
89
- ReactDOMServer . renderToString (
91
+ renderToStringStrict (
90
92
< StaticRouter location = "/" context = { { } } >
91
93
{ renderRoutes ( routes ) }
92
94
</ StaticRouter >
@@ -117,7 +119,7 @@ describe("renderRoutes", () => {
117
119
}
118
120
] ;
119
121
120
- ReactDOMServer . renderToString (
122
+ renderToStringStrict (
121
123
< StaticRouter location = "/" context = { { } } >
122
124
{ renderRoutes ( routes ) }
123
125
</ StaticRouter >
@@ -171,7 +173,7 @@ describe("renderRoutes", () => {
171
173
initialEntries : [ "/one" ]
172
174
} ) ;
173
175
174
- ReactDOM . render (
176
+ renderStrict (
175
177
< Router history = { history } > { renderRoutes ( routes ) } </ Router > ,
176
178
node
177
179
) ;
@@ -209,7 +211,7 @@ describe("renderRoutes", () => {
209
211
}
210
212
] ;
211
213
212
- ReactDOMServer . renderToString (
214
+ renderToStringStrict (
213
215
< StaticRouter location = "/two" context = { { } } >
214
216
{ renderRoutes ( routes , { } , { location : { pathname : "/one" } } ) }
215
217
</ StaticRouter >
@@ -241,7 +243,7 @@ describe("renderRoutes", () => {
241
243
routeToMatch
242
244
] ;
243
245
244
- ReactDOMServer . renderToString (
246
+ renderToStringStrict (
245
247
< StaticRouter location = "/path/child" context = { { } } >
246
248
{ renderRoutes ( routes ) }
247
249
</ StaticRouter >
@@ -268,12 +270,12 @@ describe("renderRoutes", () => {
268
270
}
269
271
] ;
270
272
271
- ReactDOMServer . renderToString (
273
+ renderToStringStrict (
272
274
< StaticRouter location = "/path/child" context = { { } } >
273
275
{ renderRoutes ( routes ) }
274
276
</ StaticRouter >
275
277
) ;
276
- ReactDOMServer . renderToString (
278
+ renderToStringStrict (
277
279
< StaticRouter location = "/" context = { { } } >
278
280
{ renderRoutes ( routes ) }
279
281
</ StaticRouter >
@@ -303,12 +305,12 @@ describe("renderRoutes", () => {
303
305
}
304
306
] ;
305
307
306
- ReactDOMServer . renderToString (
308
+ renderToStringStrict (
307
309
< StaticRouter location = "/path/child/grandchild" context = { { } } >
308
310
{ renderRoutes ( routes ) }
309
311
</ StaticRouter >
310
312
) ;
311
- ReactDOMServer . renderToString (
313
+ renderToStringStrict (
312
314
< StaticRouter location = "/path" context = { { } } >
313
315
{ renderRoutes ( routes ) }
314
316
</ StaticRouter >
@@ -339,7 +341,7 @@ describe("renderRoutes", () => {
339
341
routeToMatch
340
342
] ;
341
343
342
- ReactDOMServer . renderToString (
344
+ renderToStringStrict (
343
345
< StaticRouter location = "/path/" context = { { } } >
344
346
{ renderRoutes ( routes ) }
345
347
</ StaticRouter >
@@ -366,17 +368,17 @@ describe("renderRoutes", () => {
366
368
}
367
369
] ;
368
370
369
- ReactDOMServer . renderToString (
371
+ renderToStringStrict (
370
372
< StaticRouter location = "/path/child" context = { { } } >
371
373
{ renderRoutes ( routes ) }
372
374
</ StaticRouter >
373
375
) ;
374
- ReactDOMServer . renderToString (
376
+ renderToStringStrict (
375
377
< StaticRouter location = "/" context = { { } } >
376
378
{ renderRoutes ( routes ) }
377
379
</ StaticRouter >
378
380
) ;
379
- ReactDOMServer . renderToString (
381
+ renderToStringStrict (
380
382
< StaticRouter location = "/path" context = { { } } >
381
383
{ renderRoutes ( routes ) }
382
384
</ StaticRouter >
@@ -418,16 +420,18 @@ describe("renderRoutes", () => {
418
420
}
419
421
] ;
420
422
421
- ReactDOMServer . renderToString (
423
+ renderToStringStrict (
422
424
< StaticRouter location = "/path/child/grandchild" context = { { } } >
423
425
{ renderRoutes ( routes ) }
424
426
</ StaticRouter >
425
427
) ;
426
- ReactDOMServer . renderToString (
428
+
429
+ renderToStringStrict (
427
430
< StaticRouter location = "/path/" context = { { } } >
428
431
{ renderRoutes ( routes ) }
429
432
</ StaticRouter >
430
433
) ;
434
+
431
435
expect ( renderedRoutes . length ) . toEqual ( 2 ) ;
432
436
expect ( renderedRoutes [ 0 ] ) . toEqual ( routes [ 1 ] ) ;
433
437
expect ( renderedRoutes [ 1 ] ) . toEqual ( routes [ 1 ] . routes [ 1 ] ) ;
@@ -442,11 +446,12 @@ describe("renderRoutes", () => {
442
446
}
443
447
] ;
444
448
445
- ReactDOMServer . renderToString (
449
+ renderToStringStrict (
446
450
< StaticRouter location = "/path" context = { { } } >
447
451
{ renderRoutes ( routes ) }
448
452
</ StaticRouter >
449
453
) ;
454
+
450
455
expect ( renderedRoutes . length ) . toEqual ( 1 ) ;
451
456
expect ( renderedRoutes [ 0 ] ) . toEqual ( routes [ 0 ] ) ;
452
457
} ) ;
0 commit comments