core-vapor icon indicating copy to clipboard operation
core-vapor copied to clipboard

Unhandled component async emit error

Open xiaodong2008 opened this issue 8 months ago • 0 comments

Test Case:

test('in component event handler via emit (async)', async () => {
  const err = new Error('foo')
  const fn = vi.fn()
  const Comp = {
    setup() {
      onErrorCaptured((err, instance, info) => {
        fn(err, info)
        return false
      })
      return createComponent(Child, {
        async onFoo() {
          throw err
        },
      })
    },
  }
  const Child = {
    props: ['onFoo'],
    setup(props: any, { emit }: any) {
      emit('foo')
    },
  }
  define(Comp).render()
  await nextTick()
  expect(fn).toHaveBeenCalledWith(err, 'setup function')
})

Error:

Vitest caught 2 unhandled errors during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

Error: foo
 ❯ packages/runtime-vapor/__tests__/errorHandling.spec.ts:383:17
    381| 
    382|   test('in component event handler via emit (async)', async () => {
    383|     const err = new Error('foo')
       |                 ^
    384|     const fn = vi.fn()
    385| 
 ❯ node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:135:14
 ❯ node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:60:26
 ❯ runTest node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:771:17
 ❯ runSuite node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:899:15
 ❯ runSuite node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:899:15
 ❯ runFiles node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:948:5
 ❯ startTests node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:957:3
 ❯ node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vitest/dist/chunks/runtime-runBaseTests.-x-nNuJ_.js:116:7
 ❯ withEnv node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vitest/dist/chunks/runtime-runBaseTests.-x-nNuJ_.js:83:5

This error originated in "packages/runtime-vapor/__tests__/errorHandling.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.

Error: foo
 ❯ packages/runtime-vapor/__tests__/errorHandling.spec.ts:383:17
    381| 
    382|   test('in component event handler via emit (async)', async () => {
    383|     const err = new Error('foo')
       |                 ^
    384|     const fn = vi.fn()
    385| 
 ❯ node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:135:14
 ❯ node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:60:26
 ❯ runTest node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:771:17
 ❯ runSuite node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:899:15
 ❯ runSuite node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:899:15
 ❯ runFiles node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:948:5
 ❯ startTests node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:957:3
 ❯ node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vitest/dist/chunks/runtime-runBaseTests.-x-nNuJ_.js:116:7
 ❯ withEnv node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vitest/dist/chunks/runtime-runBaseTests.-x-nNuJ_.js:83:5

This error originated in "packages/runtime-vapor/__tests__/errorHandling.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.

 Test Files  1 failed (1)
      Tests  1 failed | 12 passed (13)
     Errors  2 errors
   Start at  13:34:46
   Duration  75ms

xiaodong2008 avatar Jun 21 '24 05:06 xiaodong2008