File tree 2 files changed +55
-1
lines changed
test/unit/features/component
2 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ export default {
87
87
if ( componentOptions ) {
88
88
// check pattern
89
89
const name : ?string = getComponentName ( componentOptions )
90
- if ( name && (
90
+ if ( ! name || (
91
91
( this . exclude && matches ( this . exclude , name ) ) ||
92
92
( this . include && ! matches ( this . include , name ) )
93
93
) ) {
Original file line number Diff line number Diff line change @@ -550,6 +550,60 @@ describe('Component keep-alive', () => {
550
550
expect ( `Unknown custom element: <foo>` ) . toHaveBeenWarned ( )
551
551
} )
552
552
553
+ // #6938
554
+ it ( 'should not cache anonymous component' , done => {
555
+ const Foo = {
556
+ name : 'foo' ,
557
+ template : `<div>foo</div>` ,
558
+ created : jasmine . createSpy ( 'foo' )
559
+ }
560
+
561
+ const Bar = {
562
+ template : `<div>bar</div>` ,
563
+ created : jasmine . createSpy ( 'bar' )
564
+ }
565
+
566
+ const Child = {
567
+ functional : true ,
568
+ render ( h , ctx ) {
569
+ return h ( ctx . props . view ? Foo : Bar )
570
+ }
571
+ }
572
+
573
+ const vm = new Vue ( {
574
+ template : `
575
+ <keep-alive include="foo">
576
+ <child :view="view"></child>
577
+ </keep-alive>
578
+ ` ,
579
+ data : {
580
+ view : true
581
+ } ,
582
+ components : { Child }
583
+ } ) . $mount ( )
584
+
585
+ function assert ( foo , bar ) {
586
+ expect ( Foo . created . calls . count ( ) ) . toBe ( foo )
587
+ expect ( Bar . created . calls . count ( ) ) . toBe ( bar )
588
+ }
589
+
590
+ expect ( vm . $el . textContent ) . toBe ( 'foo' )
591
+ assert ( 1 , 0 )
592
+ vm . view = false
593
+ waitForUpdate ( ( ) => {
594
+ expect ( vm . $el . textContent ) . toBe ( 'bar' )
595
+ assert ( 1 , 1 )
596
+ vm . view = true
597
+ } ) . then ( ( ) => {
598
+ expect ( vm . $el . textContent ) . toBe ( 'foo' )
599
+ assert ( 1 , 1 )
600
+ vm . view = false
601
+ } ) . then ( ( ) => {
602
+ expect ( vm . $el . textContent ) . toBe ( 'bar' )
603
+ assert ( 1 , 2 )
604
+ } ) . then ( done )
605
+ } )
606
+
553
607
if ( ! isIE9 ) {
554
608
it ( 'with transition-mode out-in' , done => {
555
609
let next
You can’t perform that action at this time.
0 commit comments