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

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

76 lines
1.3 KiB
TypeScript
Raw Normal View History

2016-05-30 01:02:45 +08:00
import Vue from 'vue'
import { nativeWatch } from 'core/util/env'
2016-05-30 01:02:45 +08:00
describe('Options extends', () => {
it('should work on objects', () => {
const A = {
data() {
return { a: 1 }
}
}
const B = {
extends: A,
data() {
return { b: 2 }
}
}
const vm = new Vue({
extends: B,
data: {
c: 3
}
})
expect(vm.a).toBe(1)
expect(vm.b).toBe(2)
expect(vm.c).toBe(3)
})
it('should work on extended constructors', () => {
const A = Vue.extend({
data() {
return { a: 1 }
}
})
const B = Vue.extend({
extends: A,
data() {
return { b: 2 }
}
})
const vm = new Vue({
extends: B,
data: {
c: 3
}
})
expect(vm.a).toBe(1)
expect(vm.b).toBe(2)
expect(vm.c).toBe(3)
})
if (nativeWatch) {
it('should work with global mixins + Object.prototype.watch', done => {
Vue.mixin({})
2017-06-06 14:48:05 +08:00
2022-05-20 07:56:02 +08:00
const spy = vi.fn()
const A = Vue.extend({
data: function () {
return { a: 1 }
},
watch: {
a: spy
},
created: function () {
this.a = 2
}
})
new Vue({
extends: A
})
waitForUpdate(() => {
expect(spy).toHaveBeenCalledWith(2, 1)
}).then(done)
})
}
})