import Vue from '@vue/compat'
import { nextTick } from '@vue/runtime-core'
import { CompilerDeprecationTypes } from '../../compiler-core/src'
import { toggleDeprecationWarning } from '../../runtime-core/src/compat/compatConfig'
import { triggerEvent } from './utils'
beforeEach(() => {
toggleDeprecationWarning(false)
Vue.configureCompat({
MODE: 2
})
})
afterEach(() => {
toggleDeprecationWarning(false)
Vue.configureCompat({ MODE: 3 })
})
// COMPILER_V_FOR_REF is tested in ./refInfor.spec.ts
// COMPILER_FILTERS is tested in ./filters.spec.ts
test('COMPILER_IS_ON_ELEMENT', () => {
const MyButton = {
template: `
`
}
const vm = new Vue({
template: ``,
components: {
MyButton
}
}).$mount()
expect(vm.$el.outerHTML).toBe(`text
`)
expect(CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT).toHaveBeenWarned()
})
test('COMPILER_IS_ON_ELEMENT (dynamic)', () => {
const MyButton = {
template: `
`
}
const vm = new Vue({
template: ``,
components: {
MyButton
}
}).$mount()
expect(vm.$el.outerHTML).toBe(`text
`)
expect(CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT).toHaveBeenWarned()
})
test('COMPILER_V_BIND_SYNC', async () => {
const MyButton = {
props: ['foo'],
template: ``
}
const vm = new Vue({
data() {
return {
foo: 0
}
},
template: ``,
components: {
MyButton
}
}).$mount()
expect(vm.$el.textContent).toBe(`0`)
triggerEvent(vm.$el, 'click')
await nextTick()
expect(vm.$el.textContent).toBe(`1`)
expect(CompilerDeprecationTypes.COMPILER_V_BIND_SYNC).toHaveBeenWarned()
})
test('COMPILER_V_BIND_PROP', () => {
const vm = new Vue({
template: ``
}).$mount()
expect(vm.$el.id).toBe('foo')
expect(CompilerDeprecationTypes.COMPILER_V_BIND_PROP).toHaveBeenWarned()
})
test('COMPILER_V_BIND_OBJECT_ORDER', () => {
const vm = new Vue({
template: ``
}).$mount()
expect(vm.$el.id).toBe('foo')
expect(vm.$el.className).toBe('baz')
expect(
CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER
).toHaveBeenWarned()
})
test('COMPILER_V_ON_NATIVE', () => {
const spy = jest.fn()
const vm = new Vue({
template: ``,
components: {
child: {
template: ``
}
},
methods: {
spy
}
}).$mount()
triggerEvent(vm.$el, 'click')
expect(spy).toHaveBeenCalledTimes(1)
expect(CompilerDeprecationTypes.COMPILER_V_ON_NATIVE).toHaveBeenWarned()
})
test('COMPILER_V_IF_V_FOR_PRECEDENCE', () => {
new Vue({ template: `` }).$mount()
expect(
CompilerDeprecationTypes.COMPILER_V_IF_V_FOR_PRECEDENCE
).toHaveBeenWarned()
})
test('COMPILER_NATIVE_TEMPLATE', () => {
const vm = new Vue({
template: ``
}).$mount()
expect(vm.$el.innerHTML).toBe(``)
expect(CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE).toHaveBeenWarned()
})
test('COMPILER_INLINE_TEMPLATE', () => {
const vm = new Vue({
template: `{{ n }}
`,
components: {
foo: {
data() {
return { n: 123 }
}
}
}
}).$mount()
expect(vm.$el.outerHTML).toBe(`123
`)
expect(CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE).toHaveBeenWarned()
})