Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled component async emit error #249

Open
xiaodong2008 opened this issue Jun 21, 2024 · 0 comments
Open

Unhandled component async emit error #249

xiaodong2008 opened this issue Jun 21, 2024 · 0 comments
Labels

Comments

@xiaodong2008
Copy link
Collaborator

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant