test: test suspense error handling

This commit is contained in:
Evan You
2019-09-12 01:52:14 -04:00
parent b378b17076
commit 3b1d87efbe
3 changed files with 102 additions and 32 deletions

View File

@@ -9,7 +9,8 @@ import {
nextTick,
onMounted,
watch,
onUnmounted
onUnmounted,
onErrorCaptured
} from '@vue/runtime-test'
describe('renderer: suspense', () => {
@@ -543,7 +544,39 @@ describe('renderer: suspense', () => {
expect(calls).toEqual([`inner mounted`, `outer mounted`])
})
test.todo('error handling')
test('error handling', async () => {
const Async = {
async setup() {
throw new Error('oops')
}
}
const Comp = {
setup() {
const error = ref<any>(null)
onErrorCaptured(e => {
error.value = e
return true
})
return () =>
error.value
? h('div', error.value.message)
: h(Suspense, null, {
default: h(Async),
fallback: h('div', 'fallback')
})
}
}
const root = nodeOps.createElement('div')
render(h(Comp), root)
expect(serializeInner(root)).toBe(`<div>fallback</div>`)
await Promise.all(deps)
await nextTick()
expect(serializeInner(root)).toBe(`<div>oops</div>`)
})
test.todo('new async dep after resolve should cause suspense to restart')