@@ -290,12 +290,16 @@ describe('Routing with async components', function() {
290
290
var aboutWasInLoadingState ;
291
291
var mainSeenPendingUpdate ;
292
292
293
+ var mainAsyncStateCount ;
294
+ var aboutAsyncStateCount ;
295
+
293
296
var App = React . createClass ( {
294
297
295
298
render : function ( ) {
296
299
return Router . Locations ( { ref : 'router' , className : 'App' } ,
297
300
Router . Location ( { path : '/__zuul' , handler : Main , ref : 'main' } ) ,
298
- Router . Location ( { path : '/__zuul/about' , handler : About , ref : 'about' } )
301
+ Router . Location ( { path : '/__zuul/about' , handler : About , ref : 'about' } ) ,
302
+ Router . Location ( { path : '/__zuul/about2' , handler : About , ref : 'about2' } )
299
303
) ;
300
304
}
301
305
} ) ;
@@ -304,6 +308,7 @@ describe('Routing with async components', function() {
304
308
mixins : [ ReactAsync . Mixin , Router . NavigatableMixin ] ,
305
309
306
310
getInitialStateAsync : function ( cb ) {
311
+ mainAsyncStateCount += 1 ;
307
312
setTimeout ( function ( ) {
308
313
cb ( null , { message : 'main' } ) ;
309
314
} , 20 ) ;
@@ -325,6 +330,7 @@ describe('Routing with async components', function() {
325
330
mixins : [ ReactAsync . Mixin ] ,
326
331
327
332
getInitialStateAsync : function ( cb ) {
333
+ aboutAsyncStateCount += 1 ;
328
334
delay ( function ( ) {
329
335
cb ( null , { message : 'about' } ) ;
330
336
} ) ;
@@ -343,25 +349,30 @@ describe('Routing with async components', function() {
343
349
aboutWasInLoadingState = false ;
344
350
345
351
mainSeenPendingUpdate = false ;
352
+
353
+ mainAsyncStateCount = 0 ;
354
+ aboutAsyncStateCount = 0 ;
346
355
} ) ;
347
356
348
357
beforeEach ( setUp ( App ) ) ;
349
358
afterEach ( cleanUp ) ;
350
359
351
360
it ( 'renders async component' , function ( done ) {
352
361
assertRendered ( 'loading...' ) ;
353
- setTimeout ( function ( ) {
362
+ delay ( 50 , function ( ) {
354
363
assertRendered ( 'main' ) ;
355
364
assert ( ! mainSeenPendingUpdate ) ;
356
365
assert ( mainWasInLoadingState ) ;
366
+ assert . equal ( mainAsyncStateCount , 1 ) ;
367
+ assert . equal ( aboutAsyncStateCount , 0 ) ;
357
368
done ( ) ;
358
- } , 50 ) ;
369
+ } ) ;
359
370
} ) ;
360
371
361
372
it ( 'renders async component and navigates' , function ( done ) {
362
373
assertRendered ( 'loading...' ) ;
363
374
364
- setTimeout ( function ( ) {
375
+ delay ( 100 , function ( ) {
365
376
assertRendered ( 'main' ) ;
366
377
367
378
router . navigate ( '/__zuul/about' , function ( err ) {
@@ -370,15 +381,17 @@ describe('Routing with async components', function() {
370
381
assert ( mainWasInLoadingState ) ;
371
382
assert ( mainSeenPendingUpdate ) ;
372
383
assert ( ! aboutWasInLoadingState ) ;
384
+ assert . equal ( mainAsyncStateCount , 1 ) ;
385
+ assert . equal ( aboutAsyncStateCount , 1 ) ;
373
386
done ( ) ;
374
387
} ) ;
375
- } , 100 ) ;
388
+ } ) ;
376
389
} ) ;
377
390
378
391
it ( 'cancels pending update on navigate' , function ( done ) {
379
392
assertRendered ( 'loading...' ) ;
380
393
381
- setTimeout ( function ( ) {
394
+ delay ( 100 , function ( ) {
382
395
assertRendered ( 'main' ) ;
383
396
384
397
router . navigate ( '/__zuul/about' , function ( err ) {
@@ -393,10 +406,37 @@ describe('Routing with async components', function() {
393
406
assert ( mainSeenPendingUpdate ) ;
394
407
assert ( mainWasInLoadingState ) ;
395
408
assert ( ! aboutWasInLoadingState ) ;
409
+ assert . equal ( mainAsyncStateCount , 1 ) ;
410
+ assert . equal ( aboutAsyncStateCount , 1 ) ;
396
411
done ( ) ;
397
412
} ) ;
398
413
399
- } , 100 ) ;
414
+ } ) ;
415
+ } ) ;
416
+
417
+ it ( 'does not trigger async state load if type of the next component is the same' , function ( done ) {
418
+ assertRendered ( 'loading...' ) ;
419
+
420
+ delay ( 100 , function ( ) {
421
+ assertRendered ( 'main' ) ;
422
+
423
+ router . navigate ( '/__zuul/about' , function ( err ) {
424
+ if ( err ) return done ( err ) ;
425
+ assertRendered ( 'about' ) ;
426
+
427
+ router . navigate ( '/__zuul/about2' , function ( err ) {
428
+ if ( err ) return done ( err ) ;
429
+ assertRendered ( 'about' ) ;
430
+ assert ( mainWasInLoadingState ) ;
431
+ assert ( mainSeenPendingUpdate ) ;
432
+ assert ( ! aboutWasInLoadingState ) ;
433
+ assert . equal ( mainAsyncStateCount , 1 ) ;
434
+ assert . equal ( aboutAsyncStateCount , 1 ) ;
435
+ done ( ) ;
436
+ } ) ;
437
+ } ) ;
438
+ } ) ;
439
+
400
440
} ) ;
401
441
} ) ;
402
442
0 commit comments