@@ -551,7 +551,7 @@ describe('Component keep-alive', () => {
551
551
} )
552
552
553
553
// #6938
554
- it ( 'should not cache anonymous component' , done => {
554
+ it ( 'should not cache anonymous component when include is specified ' , done => {
555
555
const Foo = {
556
556
name : 'foo' ,
557
557
template : `<div>foo</div>` ,
@@ -604,6 +604,58 @@ describe('Component keep-alive', () => {
604
604
} ) . then ( done )
605
605
} )
606
606
607
+ it ( 'should cache anonymous components if include is not specified' , done => {
608
+ const Foo = {
609
+ template : `<div>foo</div>` ,
610
+ created : jasmine . createSpy ( 'foo' )
611
+ }
612
+
613
+ const Bar = {
614
+ template : `<div>bar</div>` ,
615
+ created : jasmine . createSpy ( 'bar' )
616
+ }
617
+
618
+ const Child = {
619
+ functional : true ,
620
+ render ( h , ctx ) {
621
+ return h ( ctx . props . view ? Foo : Bar )
622
+ }
623
+ }
624
+
625
+ const vm = new Vue ( {
626
+ template : `
627
+ <keep-alive>
628
+ <child :view="view"></child>
629
+ </keep-alive>
630
+ ` ,
631
+ data : {
632
+ view : true
633
+ } ,
634
+ components : { Child }
635
+ } ) . $mount ( )
636
+
637
+ function assert ( foo , bar ) {
638
+ expect ( Foo . created . calls . count ( ) ) . toBe ( foo )
639
+ expect ( Bar . created . calls . count ( ) ) . toBe ( bar )
640
+ }
641
+
642
+ expect ( vm . $el . textContent ) . toBe ( 'foo' )
643
+ assert ( 1 , 0 )
644
+ vm . view = false
645
+ waitForUpdate ( ( ) => {
646
+ expect ( vm . $el . textContent ) . toBe ( 'bar' )
647
+ assert ( 1 , 1 )
648
+ vm . view = true
649
+ } ) . then ( ( ) => {
650
+ expect ( vm . $el . textContent ) . toBe ( 'foo' )
651
+ assert ( 1 , 1 )
652
+ vm . view = false
653
+ } ) . then ( ( ) => {
654
+ expect ( vm . $el . textContent ) . toBe ( 'bar' )
655
+ assert ( 1 , 1 )
656
+ } ) . then ( done )
657
+ } )
658
+
607
659
if ( ! isIE9 ) {
608
660
it ( 'with transition-mode out-in' , done => {
609
661
let next
0 commit comments