test: test case for #11286

This commit is contained in:
Evan You 2024-07-17 14:29:54 +08:00
parent c10e40a217
commit 3dc5a1ad98
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
1 changed files with 31 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import {
type VNode,
computed,
createApp,
defineComponent,
h,
@ -639,5 +640,35 @@ describe('error handling', () => {
)
})
// #11286
test('handle error in computed', async () => {
const err = new Error()
const handler = vi.fn()
const count = ref(1)
const x = computed(() => {
if (count.value === 2) throw err
return count.value + 1
})
const app = createApp({
setup() {
return () => x.value
},
})
app.config.errorHandler = handler
app.mount(nodeOps.createElement('div'))
count.value = 2
await nextTick()
expect(handler).toHaveBeenCalledWith(
err,
{},
ErrorTypeStrings[ErrorCodes.COMPONENT_UPDATE],
)
})
// native event handler handling should be tested in respective renderers
})