fix(Suspense): emit initial fallback and pending events (#3965)
Fix #3964
This commit is contained in:
committed by
GitHub
parent
43e2a72900
commit
ab6e927041
@@ -69,6 +69,70 @@ describe('Suspense', () => {
|
||||
expect(serializeInner(root)).toBe(`<div>async</div>`)
|
||||
})
|
||||
|
||||
test('emits events', async () => {
|
||||
const Async = defineAsyncComponent({
|
||||
render() {
|
||||
return h('div', 'async')
|
||||
}
|
||||
})
|
||||
|
||||
const onFallback = jest.fn()
|
||||
const onResolve = jest.fn()
|
||||
const onPending = jest.fn()
|
||||
|
||||
const show = ref(true)
|
||||
const Comp = {
|
||||
setup() {
|
||||
return () =>
|
||||
h(
|
||||
Suspense,
|
||||
{
|
||||
onFallback,
|
||||
onResolve,
|
||||
onPending,
|
||||
// force displaying the fallback right away
|
||||
timeout: 0
|
||||
},
|
||||
{
|
||||
default: () => (show.value ? h(Async) : null),
|
||||
fallback: h('div', 'fallback')
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const root = nodeOps.createElement('div')
|
||||
render(h(Comp), root)
|
||||
expect(onFallback).toHaveBeenCalledTimes(1)
|
||||
expect(onPending).toHaveBeenCalledTimes(1)
|
||||
expect(onResolve).toHaveBeenCalledTimes(0)
|
||||
|
||||
await Promise.all(deps)
|
||||
await nextTick()
|
||||
expect(onFallback).toHaveBeenCalledTimes(1)
|
||||
expect(onPending).toHaveBeenCalledTimes(1)
|
||||
expect(onResolve).toHaveBeenCalledTimes(1)
|
||||
|
||||
show.value = false
|
||||
await nextTick()
|
||||
expect(onFallback).toHaveBeenCalledTimes(1)
|
||||
expect(onPending).toHaveBeenCalledTimes(2)
|
||||
expect(onResolve).toHaveBeenCalledTimes(2)
|
||||
|
||||
deps.length = 0
|
||||
show.value = true
|
||||
await nextTick()
|
||||
expect(onFallback).toHaveBeenCalledTimes(2)
|
||||
expect(onPending).toHaveBeenCalledTimes(3)
|
||||
expect(onResolve).toHaveBeenCalledTimes(2)
|
||||
|
||||
await Promise.all(deps)
|
||||
await nextTick()
|
||||
expect(onFallback).toHaveBeenCalledTimes(2)
|
||||
expect(onPending).toHaveBeenCalledTimes(3)
|
||||
expect(onResolve).toHaveBeenCalledTimes(3)
|
||||
})
|
||||
|
||||
test('nested async deps', async () => {
|
||||
const calls: string[] = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user