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

Component error handling in 3.15 #1037

Open
romainquentel opened this issue Dec 9, 2024 · 0 comments
Open

Component error handling in 3.15 #1037

romainquentel opened this issue Dec 9, 2024 · 0 comments

Comments

@romainquentel
Copy link

Environment

  • Operating System: Linux
  • Node Version: v20.15.1
  • Nuxt Version: 3.14.1592
  • CLI Version: 3.15.0
  • Nitro Version: 2.10.4
  • Package Manager: [email protected]
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

When using test-utils v3.14 the myComponent.nuxt.spec.ts test pass:
https://stackblitz.com/edit/github-kucyss44?file=test%2FmyComponent.nuxt.spec.ts
When using test-utils v3.15 the myComponent.nuxt.spec.ts test fails:
https://stackblitz.com/edit/github-kucyss44-zywdn3sh?file=test%2FmyComponent.nuxt.spec.ts

Describe the bug

When using nuxt test-utils in v3.15, I can no longer catch errors thrown in the tested component using the errorCaptured option of mountSuspended:

let capturedError: string | null = null;

const component = await mountSuspended(MyComponent, {
  errorCaptured(err: unknown) {
    capturedError =
      typeof err === 'object' &&
      err !== null &&
      'message' in err &&
      typeof err.message === 'string'
        ? err.message
        : '';
    return false;
  },
});

expect(capturedError).toBe('This is an error');

It does work when using test-utils in v3.14. Trying to find alternatives I've also noticed that trying to catch errors using errorHandler also stopped working:

const component = await mountSuspended(MyComponent, {
  global: {
        config: {
          errorHandler(err: unknown) {
           // message displayed when using v3.14, not when using v3.15.
            console.log("error captured : ", err);
          },
        },
      }
});

It work when I replace await mountSuspended with mount from vue test-utils.

Additional context

No response

Logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant