test: fix suspense tests in Node 12
This commit is contained in:
parent
a83ee65e30
commit
95e796fdb6
@ -26,11 +26,16 @@ describe('renderer: suspense', () => {
|
|||||||
delay: number = 0
|
delay: number = 0
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
async setup(props: any, { slots }: any) {
|
setup(props: any, { slots }: any) {
|
||||||
const p: Promise<T> = new Promise(r => setTimeout(() => r(comp), delay))
|
const p = new Promise(resolve => {
|
||||||
deps.push(p)
|
setTimeout(() => {
|
||||||
const Inner = await p
|
resolve(() => h(comp, props, slots))
|
||||||
return () => h(Inner, props, slots)
|
}, delay)
|
||||||
|
})
|
||||||
|
// in Node 12, due to timer/nextTick mechanism change, we have to wait
|
||||||
|
// an extra tick to avoid race conditions
|
||||||
|
deps.push(p.then(() => Promise.resolve()))
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,13 +103,16 @@ describe('renderer: suspense', () => {
|
|||||||
const root = nodeOps.createElement('div')
|
const root = nodeOps.createElement('div')
|
||||||
render(h(Comp), root)
|
render(h(Comp), root)
|
||||||
expect(serializeInner(root)).toBe(`<div>fallback</div>`)
|
expect(serializeInner(root)).toBe(`<div>fallback</div>`)
|
||||||
|
expect(calls).toEqual([])
|
||||||
|
|
||||||
await deps[0]
|
await deps[0]
|
||||||
await nextTick()
|
await nextTick()
|
||||||
expect(serializeInner(root)).toBe(`<div>fallback</div>`)
|
expect(serializeInner(root)).toBe(`<div>fallback</div>`)
|
||||||
|
expect(calls).toEqual([])
|
||||||
|
|
||||||
await Promise.all(deps)
|
await Promise.all(deps)
|
||||||
await nextTick()
|
await nextTick()
|
||||||
|
expect(calls).toEqual([`outer mounted`, `inner mounted`])
|
||||||
expect(serializeInner(root)).toBe(`<div>inner</div>`)
|
expect(serializeInner(root)).toBe(`<div>inner</div>`)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -152,7 +160,8 @@ describe('renderer: suspense', () => {
|
|||||||
const Async = {
|
const Async = {
|
||||||
async setup() {
|
async setup() {
|
||||||
const p = new Promise(r => setTimeout(r, 1))
|
const p = new Promise(r => setTimeout(r, 1))
|
||||||
deps.push(p)
|
// extra tick needed for Node 12+
|
||||||
|
deps.push(p.then(() => Promise.resolve()))
|
||||||
|
|
||||||
watch(() => {
|
watch(() => {
|
||||||
calls.push('watch callback')
|
calls.push('watch callback')
|
||||||
|
Loading…
Reference in New Issue
Block a user