Explorar o código

test undefined method warning

Evan You %!s(int64=9) %!d(string=hai) anos
pai
achega
d0c13c7e66
Modificáronse 2 ficheiros con 10 adicións e 1 borrados
  1. 1 1
      src/core/instance/state.js
  2. 9 0
      test/unit/features/options/methods.spec.js

+ 1 - 1
src/core/instance/state.js

@@ -145,7 +145,7 @@ function initMethods (vm: Component) {
       if (methods[key] != null) {
         vm[key] = bind(methods[key], vm)
       } else if (process.env.NODE_ENV !== 'production') {
-        warn(`The method ${key} on vue instance is undefined.`, vm)
+        warn(`Method "${key}" is undefined in options.`, vm)
       }
     }
   }

+ 9 - 0
test/unit/features/options/methods.spec.js

@@ -15,4 +15,13 @@ describe('Options methods', () => {
     vm.plus()
     expect(vm.a).toBe(2)
   })
+
+  it('should warn undefined methods', () => {
+    new Vue({
+      methods: {
+        hello: undefined
+      }
+    })
+    expect(`Method "hello" is undefined in options`).toHaveBeenWarned()
+  })
 })