]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: test case for #11286
authorEvan You <evan@vuejs.org>
Wed, 17 Jul 2024 06:29:54 +0000 (14:29 +0800)
committerEvan You <evan@vuejs.org>
Wed, 17 Jul 2024 06:29:54 +0000 (14:29 +0800)
packages/runtime-core/__tests__/errorHandling.spec.ts

index cf148bd2fe6dbf375820dd30f09c2a816eeade50..4cf4ffe31268b9b4cbfc02f052e19d377b694122 100644 (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
 })