File tree 2 files changed +18
-2
lines changed
test/unit/features/options
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ import {
21
21
noop
22
22
} from '../util/index'
23
23
24
+ import BuiltinVue from '../index'
25
+
24
26
export function initState ( vm : Component ) {
25
27
vm . _watchers = [ ]
26
28
initProps ( vm )
@@ -143,12 +145,16 @@ function initMethods (vm: Component) {
143
145
if ( methods ) {
144
146
for ( const key in methods ) {
145
147
vm [ key ] = methods [ key ] == null ? noop : bind ( methods [ key ] , vm )
146
- if ( process . env . NODE_ENV !== 'production' && methods [ key ] == null ) {
147
- warn (
148
+ if ( process . env . NODE_ENV !== 'production' ) {
149
+ methods [ key ] == null && warn (
148
150
`method "${ key } " has an undefined value in the component definition. ` +
149
151
`Did you reference the function correctly?` ,
150
152
vm
151
153
)
154
+ hasOwn ( BuiltinVue . prototype , key ) && warn (
155
+ `Avoid overriding Vue's internal method "${ key } ".` ,
156
+ vm
157
+ )
152
158
}
153
159
}
154
160
}
Original file line number Diff line number Diff line change @@ -24,4 +24,14 @@ describe('Options methods', () => {
24
24
} )
25
25
expect ( `method "hello" has an undefined value in the component definition` ) . toHaveBeenWarned ( )
26
26
} )
27
+
28
+ it ( 'should warn overriding builtin methods' , ( ) => {
29
+ new Vue ( {
30
+ methods : {
31
+ $emit ( ) {
32
+ }
33
+ }
34
+ } )
35
+ expect ( `Avoid overriding Vue's internal method "$emit".` ) . toHaveBeenWarned ( )
36
+ } )
27
37
} )
You can’t perform that action at this time.
0 commit comments