Skip to content

Commit 6a15602

Browse files
committed
warn missing event handlers (ref #3430)
1 parent 238f65d commit 6a15602

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Diff for: src/core/instance/proxy.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ if (process.env.NODE_ENV !== 'production') {
2222
const isAllowedGlobal = allowedGlobals(key)
2323
if (!has && !isAllowedGlobal) {
2424
warn(
25-
`Trying to access non-existent property "${key}" while rendering. ` +
26-
`Make sure to declare reactive data properties in the data option.`,
25+
`Property or method "${key}" is not defined on the instance but ` +
26+
`referenced during render. Make sure to declare reactive data ` +
27+
`properties in the data option.`,
2728
target
2829
)
2930
}

Diff for: src/core/vdom/helpers.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import { isPrimitive } from '../util/index'
3+
import { isPrimitive, warn } from '../util/index'
44
import VNode from './vnode'
55

66
export function normalizeChildren (
@@ -82,7 +82,11 @@ export function updateListeners (
8282
for (name in on) {
8383
cur = on[name]
8484
old = oldOn[name]
85-
if (!old) {
85+
if (!cur) {
86+
process.env.NODE_ENV !== 'production' && warn(
87+
`Handler for event "${name}" is undefined.`
88+
)
89+
} else if (!old) {
8690
capture = name.charAt(0) === '!'
8791
event = capture ? name.slice(1) : name
8892
if (Array.isArray(cur)) {

Diff for: test/unit/features/directives/on.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,16 @@ describe('Directive v-on', () => {
223223
expect(spy2.calls.count()).toBe(1)
224224
}).then(done)
225225
})
226+
227+
it('warn missing handlers', () => {
228+
vm = new Vue({
229+
el,
230+
data: { none: null },
231+
template: `<div @click="none"></div>`
232+
})
233+
expect(`Handler for event "click" is undefined`).toHaveBeenWarned()
234+
expect(() => {
235+
triggerEvent(vm.$el, 'click')
236+
}).not.toThrow()
237+
})
226238
})

0 commit comments

Comments
 (0)