@@ -416,34 +416,55 @@ describe('Core', function () {
416416 }
417417 }
418418 } )
419- var spy = jasmine . createSpy ( )
419+
420+ var spy1 = jasmine . createSpy ( 'before hook 1' )
421+ router . beforeEach ( function ( transition ) {
422+ spy1 ( )
423+ setTimeout ( function ( ) {
424+ transition . next ( )
425+ } , wait )
426+ } )
427+
428+ var spy2 = jasmine . createSpy ( 'before hook 2' )
420429 router . beforeEach ( function ( transition ) {
421- spy ( )
430+ spy2 ( )
422431 if ( transition . to . path === '/no' ) {
423432 setTimeout ( function ( ) {
424433 transition . abort ( )
425434 next ( )
426- } , 100 )
435+ } , wait )
427436 } else if ( transition . to . path . indexOf ( '/redirect' ) > - 1 ) {
428437 setTimeout ( function ( ) {
429438 transition . redirect ( '/to/:id' )
430439 next2 ( )
431- } , 100 )
440+ } , wait )
432441 } else {
433442 transition . next ( )
434443 }
435444 } )
445+
436446 router . start ( App , el )
437- expect ( spy ) . toHaveBeenCalled ( )
438- expect ( router . app . $el . textContent ) . toBe ( 'default' )
439- router . go ( '/no' )
447+ expect ( spy1 ) . toHaveBeenCalled ( )
448+ expect ( spy2 ) . not . toHaveBeenCalled ( )
449+ expect ( router . app . $el . textContent ) . toBe ( '' )
450+ setTimeout ( function ( ) {
451+ expect ( spy2 ) . toHaveBeenCalled ( )
452+ expect ( router . app . $el . textContent ) . toBe ( 'default' )
453+ router . go ( '/no' )
454+ } , wait * 2 )
440455 function next ( ) {
456+ expect ( spy1 . calls . count ( ) ) . toBe ( 2 )
457+ expect ( spy2 . calls . count ( ) ) . toBe ( 2 )
441458 expect ( router . app . $el . textContent ) . toBe ( 'default' )
442459 router . go ( '/redirect/12345' )
443460 }
444461 function next2 ( ) {
445- expect ( router . app . $el . textContent ) . toBe ( 'to 12345' )
446- done ( )
462+ expect ( spy1 . calls . count ( ) ) . toBe ( 4 ) // go + redirect
463+ expect ( spy2 . calls . count ( ) ) . toBe ( 3 ) // only go at this moment
464+ setTimeout ( function ( ) {
465+ expect ( router . app . $el . textContent ) . toBe ( 'to 12345' )
466+ done ( )
467+ } , wait * 2 )
447468 }
448469 } )
449470
0 commit comments