forked from vuejs/vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.spec.js
125 lines (115 loc) · 3.27 KB
/
config.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import Vue from 'vue'
import { warn } from 'core/util/debug'
describe('Global config', () => {
it('should warn replacing config object', () => {
const originalConfig = Vue.config
Vue.config = {}
expect(Vue.config).toBe(originalConfig)
expect('Do not replace the Vue.config object').toHaveBeenWarned()
})
describe('silent', () => {
it('should be false by default', () => {
warn('foo')
expect('foo').toHaveBeenWarned()
})
it('should work when set to true', () => {
Vue.config.silent = true
warn('foo')
expect('foo').not.toHaveBeenWarned()
Vue.config.silent = false
})
})
describe('optionMergeStrategies', () => {
it('should allow defining custom option merging strategies', () => {
const spy = jasmine.createSpy('option merging')
Vue.config.optionMergeStrategies.__test__ = (parent, child, vm) => {
spy(parent, child, vm)
return child + 1
}
const Test = Vue.extend({
__test__: 1
})
expect(spy.calls.count()).toBe(1)
expect(spy).toHaveBeenCalledWith(undefined, 1, undefined)
expect(Test.options.__test__).toBe(2)
const test = new Test({
__test__: 2
})
expect(spy.calls.count()).toBe(2)
expect(spy).toHaveBeenCalledWith(2, 2, test)
expect(test.$options.__test__).toBe(3)
})
})
describe('ignoredElements', () => {
it('should work', () => {
Vue.config.ignoredElements = ['foo', /^ion-/]
new Vue({
template: `<div><foo/><ion-foo/><ion-bar/></div>`
}).$mount()
expect('Unknown custom element').not.toHaveBeenWarned()
Vue.config.ignoredElements = []
})
})
describe('async', () => {
it('does not update synchronously when true', () => {
const spy = jasmine.createSpy()
const vm = new Vue({
template: `<div :class="value"></div>`,
updated: spy,
data: { value: true }
}).$mount()
vm.value = false
expect(spy).not.toHaveBeenCalled()
})
it('updates synchronously when false', () => {
const spy = jasmine.createSpy()
Vue.config.async = false
const vm = new Vue({
template: `<div :class="value"></div>`,
updated: spy,
data: { value: true }
}).$mount()
vm.value = false
expect(spy).toHaveBeenCalled()
Vue.config.async = true
})
it('runs watchers in correct order when false', () => {
Vue.config.async = false
const vm = new Vue({
template: `
<div id="app">
{{ computed }}
</div>`,
props: ['prop'],
propsData: {
'prop': []
},
data: () => ({
data: ''
}),
computed: {
computed () {
return this.prop.join(',')
}
},
watch: {
prop: 'execute'
},
methods: {
execute () {
this.data = this.computed
}
}
}).$mount()
expect(vm.computed).toBe('')
expect(vm.data).toBe('')
vm.prop = [1, 2, 3]
expect(vm.computed).toBe('1,2,3')
expect(vm.data).toBe('1,2,3')
vm.prop.push(4, 5)
expect(vm.computed).toBe('1,2,3,4,5')
expect(vm.data).toBe('1,2,3,4,5')
Vue.config.async = true
})
})
})