Skip to content

Overriding msw mock handler does not work when using nuxt environment #1222

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

Open
AlexanderForm1 opened this issue Mar 29, 2025 · 0 comments
Open

Comments

@AlexanderForm1
Copy link

Environment

  • Operating System: Windows_NT
  • Node Version: v22.14.0
  • Nuxt Version: 3.16.1
  • CLI Version: 3.23.1
  • Nitro Version: 2.11.8
  • Package Manager: [email protected]
  • Builder: -
  • User Config: compatibilityDate, devtools, ssr
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://github.com/AlexanderForm1/nuxt-msw-override

Run npx vitest

I tried using stackblitz but for some reason an error is thrown from the vitest setup file when importing from msw.

Describe the bug

I'm trying to test a vue component that renders some data fetched from a mocked API endpoint using Mock Service Worker. I have a vitest setup file which creates the msw server with a default handler. Inside the tests I'm overriding the default handler following the steps described here.

I have two test files, one using the default test environment (happy-dom, set in vitest.config.ts) and another using the nuxt environment.

When running the test that uses happy-dom environment the component renders the data from the handler that overrides the default one and it passes.
When running the test that uses nuxt environment it fails because the component renders the data from the default handler, even though the handler is overridden at the top of the test just like in the passing test.

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