@@ -133,6 +133,69 @@ describe('Core', function () {
133
133
] , done )
134
134
} )
135
135
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
+
136
199
it ( 'route context' , function ( done ) {
137
200
Vue . config . silent = true
138
201
router = new Router ( { abstract : true } )
@@ -581,25 +644,41 @@ describe('Core', function () {
581
644
}
582
645
} )
583
646
647
+ // a synchronous hook
648
+ var spy3 = jasmine . createSpy ( 'before hook 3' )
649
+ router . beforeEach ( function ( ) {
650
+ spy3 ( )
651
+ } )
652
+
584
653
router . start ( App , el )
585
654
expect ( spy1 ) . toHaveBeenCalled ( )
586
655
expect ( spy2 ) . not . toHaveBeenCalled ( )
656
+ expect ( spy3 ) . not . toHaveBeenCalled ( )
587
657
expect ( router . app . $el . textContent ) . toBe ( '' )
658
+
588
659
setTimeout ( function ( ) {
589
660
expect ( spy2 ) . toHaveBeenCalled ( )
661
+ expect ( spy3 ) . toHaveBeenCalled ( )
590
662
expect ( router . app . $el . textContent ) . toBe ( 'default' )
591
663
router . go ( '/no' )
592
664
} , wait * 2 )
665
+
593
666
function next ( ) {
594
667
expect ( spy1 . calls . count ( ) ) . toBe ( 2 )
595
668
expect ( spy2 . calls . count ( ) ) . toBe ( 2 )
669
+ expect ( spy3 . calls . count ( ) ) . toBe ( 1 ) // aborted at 2
596
670
expect ( router . app . $el . textContent ) . toBe ( 'default' )
597
671
router . go ( '/redirect/12345' )
598
672
}
673
+
599
674
function next2 ( ) {
600
675
expect ( spy1 . calls . count ( ) ) . toBe ( 4 ) // go + redirect
601
676
expect ( spy2 . calls . count ( ) ) . toBe ( 3 ) // only go at this moment
677
+ expect ( spy3 . calls . count ( ) ) . toBe ( 1 ) // still 1
602
678
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
603
682
expect ( router . app . $el . textContent ) . toBe ( 'to 12345' )
604
683
done ( )
605
684
} , wait * 2 )
0 commit comments