Skip to content

Commit 3dc5a1a

Browse files
committed
test: test case for #11286
1 parent c10e40a commit 3dc5a1a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/runtime-core/__tests__/errorHandling.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
type VNode,
3+
computed,
34
createApp,
45
defineComponent,
56
h,
@@ -639,5 +640,35 @@ describe('error handling', () => {
639640
)
640641
})
641642

643+
// #11286
644+
test('handle error in computed', async () => {
645+
const err = new Error()
646+
const handler = vi.fn()
647+
648+
const count = ref(1)
649+
const x = computed(() => {
650+
if (count.value === 2) throw err
651+
return count.value + 1
652+
})
653+
654+
const app = createApp({
655+
setup() {
656+
return () => x.value
657+
},
658+
})
659+
660+
app.config.errorHandler = handler
661+
app.mount(nodeOps.createElement('div'))
662+
663+
count.value = 2
664+
665+
await nextTick()
666+
expect(handler).toHaveBeenCalledWith(
667+
err,
668+
{},
669+
ErrorTypeStrings[ErrorCodes.COMPONENT_UPDATE],
670+
)
671+
})
672+
642673
// native event handler handling should be tested in respective renderers
643674
})

0 commit comments

Comments
 (0)