Browse Source

warn missing event handlers (ref #3430)

dev
Evan You 8 years ago
parent
commit
6a156020ec
  1. 5
      src/core/instance/proxy.js
  2. 8
      src/core/vdom/helpers.js
  3. 12
      test/unit/features/directives/on.spec.js

5
src/core/instance/proxy.js

@ -22,8 +22,9 @@ if (process.env.NODE_ENV !== 'production') {
const isAllowedGlobal = allowedGlobals(key)
if (!has && !isAllowedGlobal) {
warn(
`Trying to access non-existent property "${key}" while rendering. ` +
`Make sure to declare reactive data properties in the data option.`,
`Property or method "${key}" is not defined on the instance but ` +
`referenced during render. Make sure to declare reactive data ` +
`properties in the data option.`,
target
)
}

8
src/core/vdom/helpers.js

@ -1,6 +1,6 @@
/* @flow */
import { isPrimitive } from '../util/index'
import { isPrimitive, warn } from '../util/index'
import VNode from './vnode'
export function normalizeChildren (
@ -82,7 +82,11 @@ export function updateListeners (
for (name in on) {
cur = on[name]
old = oldOn[name]
if (!old) {
if (!cur) {
process.env.NODE_ENV !== 'production' && warn(
`Handler for event "${name}" is undefined.`
)
} else if (!old) {
capture = name.charAt(0) === '!'
event = capture ? name.slice(1) : name
if (Array.isArray(cur)) {

12
test/unit/features/directives/on.spec.js

@ -223,4 +223,16 @@ describe('Directive v-on', () => {
expect(spy2.calls.count()).toBe(1)
}).then(done)
})
it('warn missing handlers', () => {
vm = new Vue({
el,
data: { none: null },
template: `<div @click="none"></div>`
})
expect(`Handler for event "click" is undefined`).toHaveBeenWarned()
expect(() => {
triggerEvent(vm.$el, 'click')
}).not.toThrow()
})
})

Loading…
Cancel
Save