Browse Source

test undefined method warning

dev
Evan You 8 years ago
parent
commit
d0c13c7e66
  1. 2
      src/core/instance/state.js
  2. 9
      test/unit/features/options/methods.spec.js

2
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
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()
})
})

Loading…
Cancel
Save