2016-04-24 10:47:54 +08:00
|
|
|
import Vue from 'vue'
|
2017-02-26 07:06:22 +08:00
|
|
|
import { warn } from 'core/util/debug'
|
2016-04-24 10:47:54 +08:00
|
|
|
|
2016-04-25 01:29:38 +08:00
|
|
|
describe('Global config', () => {
|
2016-06-22 23:35:33 +08:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
|
2016-04-25 01:29:38 +08:00
|
|
|
describe('silent', () => {
|
|
|
|
it('should be false by default', () => {
|
2017-02-26 07:06:22 +08:00
|
|
|
warn('foo')
|
2016-04-24 10:47:54 +08:00
|
|
|
expect('foo').toHaveBeenWarned()
|
|
|
|
})
|
|
|
|
|
2016-04-25 01:29:38 +08:00
|
|
|
it('should work when set to true', () => {
|
2016-04-24 10:47:54 +08:00
|
|
|
Vue.config.silent = true
|
2017-02-26 07:06:22 +08:00
|
|
|
warn('foo')
|
2016-04-24 10:47:54 +08:00
|
|
|
expect('foo').not.toHaveBeenWarned()
|
|
|
|
Vue.config.silent = false
|
|
|
|
})
|
|
|
|
})
|
2016-06-02 05:10:24 +08:00
|
|
|
|
2016-06-11 06:20:48 +08:00
|
|
|
describe('optionMergeStrategies', () => {
|
|
|
|
it('should allow defining custom option merging strategies', () => {
|
2022-05-20 07:56:02 +08:00
|
|
|
const spy = vi.fn()
|
2016-06-11 06:20:48 +08:00
|
|
|
Vue.config.optionMergeStrategies.__test__ = (parent, child, vm) => {
|
|
|
|
spy(parent, child, vm)
|
|
|
|
return child + 1
|
|
|
|
}
|
|
|
|
const Test = Vue.extend({
|
|
|
|
__test__: 1
|
|
|
|
})
|
2022-05-20 07:56:02 +08:00
|
|
|
expect(spy.mock.calls.length).toBe(1)
|
2016-06-11 06:20:48 +08:00
|
|
|
expect(spy).toHaveBeenCalledWith(undefined, 1, undefined)
|
|
|
|
expect(Test.options.__test__).toBe(2)
|
|
|
|
const test = new Test({
|
|
|
|
__test__: 2
|
|
|
|
})
|
2022-05-20 07:56:02 +08:00
|
|
|
expect(spy.mock.calls.length).toBe(2)
|
2016-06-11 06:20:48 +08:00
|
|
|
expect(spy).toHaveBeenCalledWith(2, 2, test)
|
|
|
|
expect(test.$options.__test__).toBe(3)
|
|
|
|
})
|
|
|
|
})
|
2017-10-12 21:54:17 +08:00
|
|
|
|
|
|
|
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 = []
|
|
|
|
})
|
|
|
|
})
|
2018-08-17 04:26:02 +08:00
|
|
|
|
|
|
|
describe('async', () => {
|
|
|
|
it('does not update synchronously when true', () => {
|
2022-05-20 07:56:02 +08:00
|
|
|
const spy = vi.fn()
|
2018-08-17 04:26:02 +08:00
|
|
|
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', () => {
|
2022-05-20 07:56:02 +08:00
|
|
|
const spy = vi.fn()
|
2018-08-17 04:26:02 +08:00
|
|
|
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')
|
|
|
|
|
2023-12-06 15:21:00 +08:00
|
|
|
vm.prop = [...vm.prop, 4, 5]
|
2018-08-17 04:26:02 +08:00
|
|
|
expect(vm.computed).toBe('1,2,3,4,5')
|
|
|
|
expect(vm.data).toBe('1,2,3,4,5')
|
|
|
|
Vue.config.async = true
|
|
|
|
})
|
|
|
|
})
|
2016-04-24 10:47:54 +08:00
|
|
|
})
|