@@ -121,6 +121,193 @@ describe('dom', () => {
121
121
expect ( A . prototype . componentWillUnmount ) . to . have . been . calledOnce ;
122
122
} ) ;
123
123
124
+ it ( 'should support nested routers with default' , ( ) => {
125
+ class X {
126
+ componentWillMount ( ) { }
127
+ componentWillUnmount ( ) { }
128
+ render ( ) { return < div /> ; }
129
+ }
130
+ sinon . spy ( X . prototype , 'componentWillMount' ) ;
131
+ sinon . spy ( X . prototype , 'componentWillUnmount' ) ;
132
+ class Y {
133
+ componentWillMount ( ) { }
134
+ componentWillUnmount ( ) { }
135
+ render ( ) { return < div /> ; }
136
+ }
137
+ sinon . spy ( Y . prototype , 'componentWillMount' ) ;
138
+ sinon . spy ( Y . prototype , 'componentWillUnmount' ) ;
139
+ mount (
140
+ < Router base = "/app" >
141
+ < X path = "/x" />
142
+ < Router default >
143
+ < Y path = "/y" />
144
+ </ Router >
145
+ </ Router >
146
+ ) ;
147
+ expect ( X . prototype . componentWillMount ) . not . to . have . been . called ;
148
+ expect ( Y . prototype . componentWillMount ) . not . to . have . been . called ;
149
+ route ( '/app/x' ) ;
150
+ expect ( X . prototype . componentWillMount ) . to . have . been . calledOnce ;
151
+ expect ( X . prototype . componentWillUnmount ) . not . to . have . been . called ;
152
+ expect ( Y . prototype . componentWillMount ) . not . to . have . been . called ;
153
+ expect ( Y . prototype . componentWillUnmount ) . not . to . have . been . called ;
154
+ route ( '/app/y' ) ;
155
+ expect ( X . prototype . componentWillMount ) . to . have . been . calledOnce ;
156
+ expect ( X . prototype . componentWillUnmount ) . to . have . been . calledOnce ;
157
+ expect ( Y . prototype . componentWillMount ) . to . have . been . calledOnce ;
158
+ expect ( Y . prototype . componentWillUnmount ) . not . to . have . been . called ;
159
+ } ) ;
160
+
161
+ it ( 'should support nested routers with path' , ( ) => {
162
+ class X {
163
+ componentWillMount ( ) { }
164
+ componentWillUnmount ( ) { }
165
+ render ( ) { return < div /> ; }
166
+ }
167
+ sinon . spy ( X . prototype , 'componentWillMount' ) ;
168
+ sinon . spy ( X . prototype , 'componentWillUnmount' ) ;
169
+ class Y {
170
+ componentWillMount ( ) { }
171
+ componentWillUnmount ( ) { }
172
+ render ( ) { return < div /> ; }
173
+ }
174
+ sinon . spy ( Y . prototype , 'componentWillMount' ) ;
175
+ sinon . spy ( Y . prototype , 'componentWillUnmount' ) ;
176
+ mount (
177
+ < Router base = '/baz' >
178
+ < X path = "/j" />
179
+ < Router path = "/box/:bar*" >
180
+ < Y path = "/k" />
181
+ </ Router >
182
+ </ Router >
183
+ ) ;
184
+ expect ( X . prototype . componentWillMount ) . not . to . have . been . called ;
185
+ expect ( Y . prototype . componentWillMount ) . not . to . have . been . called ;
186
+ route ( '/baz/j' ) ;
187
+ expect ( X . prototype . componentWillMount ) . to . have . been . calledOnce ;
188
+ expect ( X . prototype . componentWillUnmount ) . not . to . have . been . called ;
189
+ expect ( Y . prototype . componentWillMount ) . not . to . have . been . called ;
190
+ expect ( Y . prototype . componentWillUnmount ) . not . to . have . been . called ;
191
+ route ( '/baz/box/k' ) ;
192
+ expect ( X . prototype . componentWillMount ) . to . have . been . calledOnce ;
193
+ expect ( X . prototype . componentWillUnmount ) . to . have . been . calledOnce ;
194
+ expect ( Y . prototype . componentWillMount ) . to . have . been . calledOnce ;
195
+ expect ( Y . prototype . componentWillUnmount ) . not . to . have . been . called ;
196
+ } ) ;
197
+
198
+ it ( 'should support deeply nested routers' , ( ) => {
199
+ class X {
200
+ componentWillMount ( ) { }
201
+ componentWillUnmount ( ) { }
202
+ render ( ) { return < div /> ; }
203
+ }
204
+ sinon . spy ( X . prototype , 'componentWillMount' ) ;
205
+ sinon . spy ( X . prototype , 'componentWillUnmount' ) ;
206
+ class Y {
207
+ componentWillMount ( ) { }
208
+ componentWillUnmount ( ) { }
209
+ render ( ) { return < div /> ; }
210
+ }
211
+ sinon . spy ( Y . prototype , 'componentWillMount' ) ;
212
+ sinon . spy ( Y . prototype , 'componentWillUnmount' ) ;
213
+ mount (
214
+ < Router base = '/baz' >
215
+ < X path = "/j" />
216
+ < z path = "/box/:bar*" >
217
+ < Router path = "/box" >
218
+ < Y path = "/k" />
219
+ </ Router >
220
+ </ z >
221
+ </ Router >
222
+ ) ;
223
+ expect ( X . prototype . componentWillMount ) . not . to . have . been . called ;
224
+ expect ( Y . prototype . componentWillMount ) . not . to . have . been . called ;
225
+ route ( '/baz/j' ) ;
226
+ expect ( X . prototype . componentWillMount ) . to . have . been . calledOnce ;
227
+ expect ( X . prototype . componentWillUnmount ) . not . to . have . been . called ;
228
+ expect ( Y . prototype . componentWillMount ) . not . to . have . been . called ;
229
+ expect ( Y . prototype . componentWillUnmount ) . not . to . have . been . called ;
230
+ route ( '/baz/box/k' ) ;
231
+ expect ( X . prototype . componentWillMount ) . to . have . been . calledOnce ;
232
+ expect ( X . prototype . componentWillUnmount ) . to . have . been . calledOnce ;
233
+ expect ( Y . prototype . componentWillMount ) . to . have . been . calledOnce ;
234
+ expect ( Y . prototype . componentWillUnmount ) . not . to . have . been . called ;
235
+ } ) ;
236
+
237
+ it ( 'should support nested routers and Match(s)' , ( ) => {
238
+ class X {
239
+ componentWillMount ( ) { }
240
+ componentWillUnmount ( ) { }
241
+ render ( ) { return < div /> ; }
242
+ }
243
+ sinon . spy ( X . prototype , 'componentWillMount' ) ;
244
+ sinon . spy ( X . prototype , 'componentWillUnmount' ) ;
245
+ class Y {
246
+ componentWillMount ( ) { }
247
+ componentWillUnmount ( ) { }
248
+ render ( ) { return < div /> ; }
249
+ }
250
+ sinon . spy ( Y . prototype , 'componentWillMount' ) ;
251
+ sinon . spy ( Y . prototype , 'componentWillUnmount' ) ;
252
+ mount (
253
+ < Router base = '/ccc' >
254
+ < X path = "/jjj" />
255
+ < Match path = "/xxx/:bar*" >
256
+ < Y path = "/kkk" />
257
+ </ Match >
258
+ </ Router >
259
+ ) ;
260
+ expect ( X . prototype . componentWillMount , 'X1' ) . not . to . have . been . called ;
261
+ expect ( Y . prototype . componentWillMount , 'Y1' ) . not . to . have . been . called ;
262
+ route ( '/ccc/jjj' ) ;
263
+ expect ( X . prototype . componentWillMount , 'X2' ) . to . have . been . calledOnce ;
264
+ expect ( X . prototype . componentWillUnmount , 'X3' ) . not . to . have . been . called ;
265
+ expect ( Y . prototype . componentWillMount , 'Y2' ) . not . to . have . been . called ;
266
+ expect ( Y . prototype . componentWillUnmount , 'Y3' ) . not . to . have . been . called ;
267
+ route ( '/ccc/xxx/kkk' ) ;
268
+ expect ( X . prototype . componentWillMount , 'X4' ) . to . have . been . calledOnce ;
269
+ expect ( X . prototype . componentWillUnmount , 'X5' ) . to . have . been . calledOnce ;
270
+ expect ( Y . prototype . componentWillMount , 'Y4' ) . to . have . been . calledOnce ;
271
+ expect ( Y . prototype . componentWillUnmount , 'Y5' ) . not . to . have . been . called ;
272
+ } ) ;
273
+
274
+ it ( 'should support nested router reset via base attr' , ( ) => {
275
+ class X {
276
+ componentWillMount ( ) { }
277
+ componentWillUnmount ( ) { }
278
+ render ( ) { return < div /> ; }
279
+ }
280
+ sinon . spy ( X . prototype , 'componentWillMount' ) ;
281
+ sinon . spy ( X . prototype , 'componentWillUnmount' ) ;
282
+ class Y {
283
+ componentWillMount ( ) { }
284
+ componentWillUnmount ( ) { }
285
+ render ( ) { return < div /> ; }
286
+ }
287
+ sinon . spy ( Y . prototype , 'componentWillMount' ) ;
288
+ sinon . spy ( Y . prototype , 'componentWillUnmount' ) ;
289
+ mount (
290
+ < Router base = '/baz' >
291
+ < X path = "/j" />
292
+ < Router path = "/:bar*" base = "/baz/foo" >
293
+ < Y path = "/k" />
294
+ </ Router >
295
+ </ Router >
296
+ ) ;
297
+ expect ( X . prototype . componentWillMount ) . not . to . have . been . called ;
298
+ expect ( Y . prototype . componentWillMount ) . not . to . have . been . called ;
299
+ route ( '/baz/j' ) ;
300
+ expect ( X . prototype . componentWillMount ) . to . have . been . calledOnce ;
301
+ expect ( X . prototype . componentWillUnmount ) . not . to . have . been . called ;
302
+ expect ( Y . prototype . componentWillMount ) . not . to . have . been . called ;
303
+ expect ( Y . prototype . componentWillUnmount ) . not . to . have . been . called ;
304
+ route ( '/baz/foo/k' ) ;
305
+ expect ( X . prototype . componentWillMount ) . to . have . been . calledOnce ;
306
+ expect ( X . prototype . componentWillUnmount ) . to . have . been . calledOnce ;
307
+ expect ( Y . prototype . componentWillMount ) . to . have . been . calledOnce ;
308
+ expect ( Y . prototype . componentWillUnmount ) . not . to . have . been . called ;
309
+ } ) ;
310
+
124
311
it ( 'should support re-routing' , done => {
125
312
class A {
126
313
componentWillMount ( ) {
0 commit comments