-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
/
extends.spec.js
75 lines (71 loc) · 1.36 KB
/
extends.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import Vue from 'vue'
import { nativeWatch } from 'core/util/env'
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({})
const spy = jasmine.createSpy('watch')
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)
})
}
})