File tree 3 files changed +21
-4
lines changed
test/unit/features/directives
3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -22,8 +22,9 @@ if (process.env.NODE_ENV !== 'production') {
22
22
const isAllowedGlobal = allowedGlobals ( key )
23
23
if ( ! has && ! isAllowedGlobal ) {
24
24
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.` ,
27
28
target
28
29
)
29
30
}
Original file line number Diff line number Diff line change 1
1
/* @flow */
2
2
3
- import { isPrimitive } from '../util/index'
3
+ import { isPrimitive , warn } from '../util/index'
4
4
import VNode from './vnode'
5
5
6
6
export function normalizeChildren (
@@ -82,7 +82,11 @@ export function updateListeners (
82
82
for ( name in on ) {
83
83
cur = on [ name ]
84
84
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 ) {
86
90
capture = name . charAt ( 0 ) === '!'
87
91
event = capture ? name . slice ( 1 ) : name
88
92
if ( Array . isArray ( cur ) ) {
Original file line number Diff line number Diff line change @@ -223,4 +223,16 @@ describe('Directive v-on', () => {
223
223
expect ( spy2 . calls . count ( ) ) . toBe ( 1 )
224
224
} ) . then ( done )
225
225
} )
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
+ } )
226
238
} )
You can’t perform that action at this time.
0 commit comments