@@ -551,7 +551,7 @@ describe('Component keep-alive', () => {
551551 } )
552552
553553 // #6938
554- it ( 'should not cache anonymous component' , done => {
554+ it ( 'should not cache anonymous component when include is specified ' , done => {
555555 const Foo = {
556556 name : 'foo' ,
557557 template : `<div>foo</div>` ,
@@ -604,6 +604,58 @@ describe('Component keep-alive', () => {
604604 } ) . then ( done )
605605 } )
606606
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+
607659 if ( ! isIE9 ) {
608660 it ( 'with transition-mode out-in' , done => {
609661 let next
0 commit comments