-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchild_spec.js
79 lines (71 loc) · 1.73 KB
/
child_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
76
77
78
79
var Vue = require('../../../../src/vue')
var _ = Vue.util
describe('Child API', function () {
var vm
beforeEach(function () {
vm = new Vue({
data: {
a: 1,
b: 1
},
directives: {
test: function () {}
}
})
})
it('default', function () {
var child = vm.$addChild()
expect(child instanceof Vue).toBe(true)
expect(child.a).toBeUndefined()
expect(child.$parent).toBe(vm)
expect(child.$root).toBe(vm)
expect(vm._children.indexOf(child)).toBe(0)
expect(_.resolveAsset(child.$options, 'directives', 'test')).toBeTruthy()
})
it('inherit scope', function () {
var child = vm.$addChild({
inherit: true,
data: {
b: 2
}
})
expect(child.a).toBe(1)
expect(child.b).toBe(2)
expect(child.constructor.prototype).toBe(vm)
})
it('with constructor', function () {
var Ctor = Vue.extend({
inherit: true,
data: function () {
return {
c: 3
}
}
})
var child = vm.$addChild({
data: {
b: 2
}
}, Ctor)
expect(child.a).toBe(1)
expect(child.b).toBe(2)
expect(child.c).toBe(3)
expect(child.constructor.options).toBe(Ctor.options)
})
it('cache constructor', function () {
var Ctor = Vue.extend({
inherit: true
})
var child1 = vm.$addChild(null, Ctor)
var child2 = vm.$addChild(null, Ctor)
expect(child1.constructor).toBe(child2.constructor)
})
it('Use proper constructor name with inherit', function () {
var Ctor = Vue.extend({
name: 'vue-test',
inherit: true
})
var child = vm.$addChild(null, Ctor)
expect(child.constructor.toString().match(/^function VueTest\s?\(/)).toBeTruthy()
})
})