Skip to content

Commit 244ea47

Browse files
committedJan 31, 2016
warn missing handler for child component v-on
1 parent ff6395e commit 244ea47

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
 

‎src/instance/internal/events.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,18 @@ export default function (Vue) {
3838
if (eventRE.test(name)) {
3939
name = name.replace(eventRE, '')
4040
handler = (vm._scope || vm._context).$eval(attrs[i].value, true)
41-
handler._fromParent = true
42-
vm.$on(name.replace(eventRE), handler)
41+
if (typeof handler === 'function') {
42+
handler._fromParent = true
43+
vm.$on(name.replace(eventRE), handler)
44+
} else if (process.env.NODE_ENV !== 'production') {
45+
warn(
46+
'v-on:' + name + '="' + attrs[i].value + '"' + (
47+
vm.$options.name
48+
? ' on component <' + vm.$options.name + '>'
49+
: ''
50+
) + ' expects a function value, got ' + handler
51+
)
52+
}
4353
}
4454
}
4555
}

‎test/unit/specs/instance/events_spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ describe('Instance Events', function () {
237237
expect(vm.a).toBe(1)
238238
})
239239

240+
it('warn missing handler for child component v-on', function () {
241+
new Vue({
242+
el: document.createElement('div'),
243+
template: '<comp @test="onThat"></comp>',
244+
components: {
245+
comp: {}
246+
}
247+
})
248+
expect(hasWarned(
249+
'v-on:test="onThat" on component <comp> expects a function value'
250+
)).toBe(true)
251+
})
252+
240253
it('passing $arguments', function () {
241254
new Vue({
242255
el: document.createElement('div'),

0 commit comments

Comments
 (0)
Please sign in to comment.