File tree 2 files changed +36
-4
lines changed
test/unit/features/component
2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -92,10 +92,13 @@ export function updateListeners (
92
92
if ( Array . isArray ( cur ) ) {
93
93
add ( event , ( cur . invoker = arrInvoker ( cur ) ) , capture )
94
94
} else {
95
- fn = cur
96
- cur = on [ name ] = { }
97
- cur . fn = fn
98
- add ( event , ( cur . invoker = fnInvoker ( cur ) ) , capture )
95
+ if ( ! cur . invoker ) {
96
+ fn = cur
97
+ cur = on [ name ] = { }
98
+ cur . fn = fn
99
+ cur . invoker = fnInvoker ( cur )
100
+ }
101
+ add ( event , cur . invoker , capture )
99
102
}
100
103
} else if ( Array . isArray ( old ) ) {
101
104
old . length = cur . length
@@ -126,6 +129,7 @@ function arrInvoker (arr: Array<Function>): Function {
126
129
function fnInvoker ( o : { fn : Function } ) : Function {
127
130
return function ( ev ) {
128
131
const single = arguments . length === 1
132
+ if ( typeof o . fn !== 'function' ) debugger
129
133
single ? o . fn ( ev ) : o . fn . apply ( null , arguments )
130
134
}
131
135
}
Original file line number Diff line number Diff line change @@ -481,4 +481,32 @@ describe('Component slot', () => {
481
481
} ) . $mount ( )
482
482
expect ( 'Static <slot> found inside v-for' ) . toHaveBeenWarned ( )
483
483
} )
484
+
485
+ // #3518
486
+ fit ( 'events should not break when slot is toggled by v-if' , done => {
487
+ const spy = jasmine . createSpy ( )
488
+ const vm = new Vue ( {
489
+ template : `<test><div class="click" @click="test">hi</div></test>` ,
490
+ methods : {
491
+ test : spy
492
+ } ,
493
+ components : {
494
+ test : {
495
+ data : ( ) => ( {
496
+ toggle : true
497
+ } ) ,
498
+ template : `<div v-if="toggle"><slot></slot></div>`
499
+ }
500
+ }
501
+ } ) . $mount ( )
502
+
503
+ expect ( vm . $el . textContent ) . toBe ( 'hi' )
504
+ vm . $children [ 0 ] . toggle = false
505
+ waitForUpdate ( ( ) => {
506
+ vm . $children [ 0 ] . toggle = true
507
+ } ) . then ( ( ) => {
508
+ triggerEvent ( vm . $el . querySelector ( '.click' ) , 'click' )
509
+ expect ( spy ) . toHaveBeenCalled ( )
510
+ } ) . then ( done )
511
+ } )
484
512
} )
You can’t perform that action at this time.
0 commit comments