@@ -494,7 +494,25 @@ describe('KeepAlive', () => {
494
494
return { viewRef, includeRef }
495
495
}
496
496
497
- test ( 'on include/exclude change' , async ( ) => {
497
+ function setupExclude ( ) {
498
+ const viewRef = ref ( 'one' )
499
+ const excludeRef = ref ( '' )
500
+ const App = {
501
+ render ( ) {
502
+ return h (
503
+ KeepAlive ,
504
+ {
505
+ exclude : excludeRef . value
506
+ } ,
507
+ ( ) => h ( views [ viewRef . value ] )
508
+ )
509
+ }
510
+ }
511
+ render ( h ( App ) , root )
512
+ return { viewRef, excludeRef }
513
+ }
514
+
515
+ test ( 'on include change' , async ( ) => {
498
516
const { viewRef, includeRef } = setup ( )
499
517
500
518
viewRef . value = 'two'
@@ -513,7 +531,26 @@ describe('KeepAlive', () => {
513
531
assertHookCalls ( two , [ 1 , 1 , 1 , 1 , 0 ] )
514
532
} )
515
533
516
- test ( 'on include/exclude change + view switch' , async ( ) => {
534
+ test ( 'on exclude change' , async ( ) => {
535
+ const { viewRef, excludeRef } = setupExclude ( )
536
+
537
+ viewRef . value = 'two'
538
+ await nextTick ( )
539
+ assertHookCalls ( one , [ 1 , 1 , 1 , 1 , 0 ] )
540
+ assertHookCalls ( two , [ 1 , 1 , 1 , 0 , 0 ] )
541
+
542
+ excludeRef . value = 'one'
543
+ await nextTick ( )
544
+ assertHookCalls ( one , [ 1 , 1 , 1 , 1 , 1 ] )
545
+ assertHookCalls ( two , [ 1 , 1 , 1 , 0 , 0 ] )
546
+
547
+ viewRef . value = 'one'
548
+ await nextTick ( )
549
+ assertHookCalls ( one , [ 2 , 2 , 1 , 1 , 1 ] )
550
+ assertHookCalls ( two , [ 1 , 1 , 1 , 1 , 0 ] )
551
+ } )
552
+
553
+ test ( 'on include change + view switch' , async ( ) => {
517
554
const { viewRef, includeRef } = setup ( )
518
555
519
556
viewRef . value = 'two'
@@ -529,6 +566,22 @@ describe('KeepAlive', () => {
529
566
assertHookCalls ( two , [ 1 , 1 , 1 , 1 , 1 ] )
530
567
} )
531
568
569
+ test ( 'on exclude change + view switch' , async ( ) => {
570
+ const { viewRef, excludeRef } = setupExclude ( )
571
+
572
+ viewRef . value = 'two'
573
+ await nextTick ( )
574
+ assertHookCalls ( one , [ 1 , 1 , 1 , 1 , 0 ] )
575
+ assertHookCalls ( two , [ 1 , 1 , 1 , 0 , 0 ] )
576
+
577
+ excludeRef . value = 'two'
578
+ viewRef . value = 'one'
579
+ await nextTick ( )
580
+ assertHookCalls ( one , [ 1 , 1 , 2 , 1 , 0 ] )
581
+ // two should be pruned
582
+ assertHookCalls ( two , [ 1 , 1 , 1 , 1 , 1 ] )
583
+ } )
584
+
532
585
test ( 'should not prune current active instance' , async ( ) => {
533
586
const { viewRef, includeRef } = setup ( )
534
587
0 commit comments