wip: compat test coverage
This commit is contained in:
@@ -59,4 +59,24 @@ describe('COMPONENT_ASYNC', () => {
|
||||
)
|
||||
).toHaveBeenWarned()
|
||||
})
|
||||
|
||||
test('object syntax', async () => {
|
||||
const comp = () => ({
|
||||
component: Promise.resolve({ template: 'foo' })
|
||||
})
|
||||
|
||||
const vm = new Vue({
|
||||
template: `<div><comp/></div>`,
|
||||
components: { comp }
|
||||
}).$mount()
|
||||
expect(vm.$el.innerHTML).toBe(`<!---->`)
|
||||
await timeout(0)
|
||||
expect(vm.$el.innerHTML).toBe(`foo`)
|
||||
|
||||
expect(
|
||||
(deprecationData[DeprecationTypes.COMPONENT_ASYNC].message as Function)(
|
||||
comp
|
||||
)
|
||||
).toHaveBeenWarned()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Vue from '@vue/compat'
|
||||
import { effect, isReactive } from '@vue/reactivity'
|
||||
import { nextTick } from '@vue/runtime-core'
|
||||
import {
|
||||
DeprecationTypes,
|
||||
deprecationData,
|
||||
@@ -333,4 +334,50 @@ describe('GLOBAL_PRIVATE_UTIL', () => {
|
||||
deprecationData[DeprecationTypes.GLOBAL_PRIVATE_UTIL].message
|
||||
).toHaveBeenWarned()
|
||||
})
|
||||
|
||||
test('defineReactive on instance', async () => {
|
||||
const vm = new Vue({
|
||||
beforeCreate() {
|
||||
// @ts-ignore
|
||||
Vue.util.defineReactive(this, 'foo', 1)
|
||||
},
|
||||
template: `<div>{{ foo }}</div>`
|
||||
}).$mount() as any
|
||||
expect(vm.$el.textContent).toBe('1')
|
||||
vm.foo = 2
|
||||
await nextTick()
|
||||
expect(vm.$el.textContent).toBe('2')
|
||||
})
|
||||
|
||||
test('defineReactive with object value', () => {
|
||||
const obj: any = {}
|
||||
const val = { a: 1 }
|
||||
// @ts-ignore
|
||||
Vue.util.defineReactive(obj, 'foo', val)
|
||||
|
||||
let n
|
||||
effect(() => {
|
||||
n = obj.foo.a
|
||||
})
|
||||
expect(n).toBe(1)
|
||||
// mutating original
|
||||
val.a++
|
||||
expect(n).toBe(2)
|
||||
})
|
||||
|
||||
test('defineReactive with array value', () => {
|
||||
const obj: any = {}
|
||||
const val = [1]
|
||||
// @ts-ignore
|
||||
Vue.util.defineReactive(obj, 'foo', val)
|
||||
|
||||
let n
|
||||
effect(() => {
|
||||
n = obj.foo.length
|
||||
})
|
||||
expect(n).toBe(1)
|
||||
// mutating original
|
||||
val.push(2)
|
||||
expect(n).toBe(2)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -123,9 +123,29 @@ describe('compat: render function', () => {
|
||||
})
|
||||
).toMatchObject({
|
||||
props: {
|
||||
onClick: fn, // should dedupe
|
||||
onClick: fn,
|
||||
onClickNative: fn,
|
||||
onFooBar: fn,
|
||||
'onBar-baz': fn
|
||||
'onBar-bazNative': fn
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('v2 legacy event prefixes', () => {
|
||||
const fn = () => {}
|
||||
expect(
|
||||
h('div', {
|
||||
on: {
|
||||
'&click': fn,
|
||||
'~keyup': fn,
|
||||
'!touchend': fn
|
||||
}
|
||||
})
|
||||
).toMatchObject({
|
||||
props: {
|
||||
onClickPassive: fn,
|
||||
onKeyupOnce: fn,
|
||||
onTouchendCapture: fn
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user