vue2/test/unit/features/options/methods.spec.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2016-05-31 23:21:41 +08:00
import Vue from 'vue'
import testObjectOption from '../../../helpers/test-object-option'
2016-05-31 23:21:41 +08:00
describe('Options methods', () => {
testObjectOption('methods')
2016-05-31 23:21:41 +08:00
it('should have correct context', () => {
const vm = new Vue({
data: {
a: 1
},
methods: {
plus() {
this.a++
}
}
})
vm.plus()
expect(vm.a).toBe(2)
})
2016-09-13 20:42:53 +08:00
it('should warn methods of not function type', () => {
2016-09-13 20:42:53 +08:00
new Vue({
methods: {
hello: {}
2016-09-13 20:42:53 +08:00
}
})
expect(
'Method "hello" has type "object" in the component definition'
).toHaveBeenWarned()
2016-09-13 20:42:53 +08:00
})
it('should warn methods conflicting with data', () => {
new Vue({
data: {
foo: 1
},
methods: {
foo() {}
}
})
expect(
`Method "foo" has already been defined as a data property`
).toHaveBeenWarned()
})
it('should warn methods conflicting with internal methods', () => {
new Vue({
methods: {
_update() {}
}
})
expect(
`Method "_update" conflicts with an existing Vue instance method`
).toHaveBeenWarned()
})
2016-05-31 23:21:41 +08:00
})