@@ -133,6 +133,69 @@ describe('Core', function () {
133133 ] , done )
134134 } )
135135
136+ it ( 'matching nested views with keep-alive' , function ( done ) {
137+ router = new Router ( { abstract : true } )
138+ var spyA = jasmine . createSpy ( )
139+ var spySubA = jasmine . createSpy ( )
140+ router . map ( {
141+ '/a' : {
142+ component : {
143+ template : 'VIEW A <router-view></router-view>' ,
144+ created : spyA
145+ } ,
146+ subRoutes : {
147+ '/' : {
148+ component : {
149+ template : 'SUB A DEFAULT'
150+ }
151+ } ,
152+ '/sub-a' : {
153+ component : {
154+ template : 'SUB A'
155+ }
156+ } ,
157+ '/sub-a-2' : {
158+ component : {
159+ template : 'SUB A2' ,
160+ created : spySubA
161+ }
162+ }
163+ }
164+ } ,
165+ '/b' : {
166+ component : {
167+ template : 'VIEW B <router-view></router-view>'
168+ } ,
169+ subRoutes : {
170+ '/sub-b' : {
171+ component : {
172+ template : 'SUB B'
173+ }
174+ }
175+ }
176+ }
177+ } )
178+ var App = Vue . extend ( {
179+ template : '<div><router-view keep-alive></router-view></div>'
180+ } )
181+ router . start ( App , el )
182+ assertRoutes ( [
183+ [ '/a' , 'VIEW A SUB A DEFAULT' ] ,
184+ [ '/a/sub-a' , 'VIEW A SUB A' ] ,
185+ [ '/a/sub-a-2' , 'VIEW A SUB A2' ] ,
186+ [ '/b/sub-b' , 'VIEW B SUB B' ] ,
187+ // revisit a kept-alive view
188+ [ '/a/sub-a-2' , 'VIEW A SUB A2' ] ,
189+ [ '/b' , 'VIEW B ' ] ,
190+ // no match
191+ [ '/b/sub-a' , '' ]
192+ ] , function ( ) {
193+ expect ( spyA . calls . count ( ) ) . toBe ( 1 )
194+ expect ( spySubA . calls . count ( ) ) . toBe ( 1 )
195+ done ( )
196+ } )
197+ } )
198+
136199 it ( 'route context' , function ( done ) {
137200 Vue . config . silent = true
138201 router = new Router ( { abstract : true } )
@@ -581,25 +644,41 @@ describe('Core', function () {
581644 }
582645 } )
583646
647+ // a synchronous hook
648+ var spy3 = jasmine . createSpy ( 'before hook 3' )
649+ router . beforeEach ( function ( ) {
650+ spy3 ( )
651+ } )
652+
584653 router . start ( App , el )
585654 expect ( spy1 ) . toHaveBeenCalled ( )
586655 expect ( spy2 ) . not . toHaveBeenCalled ( )
656+ expect ( spy3 ) . not . toHaveBeenCalled ( )
587657 expect ( router . app . $el . textContent ) . toBe ( '' )
658+
588659 setTimeout ( function ( ) {
589660 expect ( spy2 ) . toHaveBeenCalled ( )
661+ expect ( spy3 ) . toHaveBeenCalled ( )
590662 expect ( router . app . $el . textContent ) . toBe ( 'default' )
591663 router . go ( '/no' )
592664 } , wait * 2 )
665+
593666 function next ( ) {
594667 expect ( spy1 . calls . count ( ) ) . toBe ( 2 )
595668 expect ( spy2 . calls . count ( ) ) . toBe ( 2 )
669+ expect ( spy3 . calls . count ( ) ) . toBe ( 1 ) // aborted at 2
596670 expect ( router . app . $el . textContent ) . toBe ( 'default' )
597671 router . go ( '/redirect/12345' )
598672 }
673+
599674 function next2 ( ) {
600675 expect ( spy1 . calls . count ( ) ) . toBe ( 4 ) // go + redirect
601676 expect ( spy2 . calls . count ( ) ) . toBe ( 3 ) // only go at this moment
677+ expect ( spy3 . calls . count ( ) ) . toBe ( 1 ) // still 1
602678 setTimeout ( function ( ) {
679+ expect ( spy1 . calls . count ( ) ) . toBe ( 4 )
680+ expect ( spy2 . calls . count ( ) ) . toBe ( 4 )
681+ expect ( spy3 . calls . count ( ) ) . toBe ( 2 ) // after redirect
603682 expect ( router . app . $el . textContent ) . toBe ( 'to 12345' )
604683 done ( )
605684 } , wait * 2 )
0 commit comments