8000 add test for inline-statement event propagation · vuejs/vue@21dd64a · GitHub
[go: up one dir, main page]

Skip to content

Commit 21dd64a

Browse files
committed
add test for inline-statement event propagation
1 parent 52e8638 commit 21dd64a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test/unit/specs/api/events_spec.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,56 @@ describe('Events API', function () {
154154
expect(spy.calls.count()).toBe(2)
155155
})
156156

157+
it('handle $dispatch by v-on inline-statement', function () {
158+
var parent = new Vue({
159+
el: document.createElement('div'),
160+
template: '<child1 @test="onTest()" v-ref:child></child1>',
161+
methods: {
162+
onTest: function () {
163+
spy()
164+
}
165+
},
166+
components: {
167+
child1: {
168+
template: '<child2 @test="onTest()" v-ref:child></child2>',
169+
methods: {
170+
onTest: function () {
171+
spy()
172+
}
173+
},
174+
components: {
175+
child2: {
176+
template: '<child3 @test="onTest()" v-ref:child></child3>',
177+
methods: {
178+
onTest: function () {
179+
spy()
180+
return true
181+
}
182+
},
183+
components: {
184+
child3: {
185+
template: '<child4 v-ref:child></child4>',
186+
// `v-on` on component will be treat as its inner handler
187+
// so propagation cancelling is ignored on `<child4 @test="handler">`
188+
components: {
189+
child4: {}
190+
}
191+
}
192+
}
193+
}
194+
}
195+
}
196+
}
197+
})
198+
parent
199+
.$refs.child // child1
200+
.$refs.child // child2
201+
.$refs.child // child3
202+
.$refs.child // child4
203+
.$dispatch('test')
204+
expect(spy.calls.count()).toBe(2)
205+
})
206+
157207
it('$dispatch cancel', function () {
158208
var child = new Vue({ parent: vm })
159209
var child2 = new Vue({ parent: child })

0 commit comments

Comments
 (0)
0