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

Unable to use with msw to mock requests #775

Open
rinux55 opened this issue Mar 14, 2024 · 2 comments
Open

Unable to use with msw to mock requests #775

rinux55 opened this issue Mar 14, 2024 · 2 comments

Comments

@rinux55
Copy link

rinux55 commented Mar 14, 2024

Environment


  • Operating System: Darwin
  • Node Version: v18.19.1
  • Nuxt Version: 3.10.3
  • CLI Version: 3.10.1
  • Nitro Version: 2.9.3
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/~/github.com/rinux55/nuxt-fetch

See app.test.ts. In the test/setup.ts and test/server.ts there is an msw server being set up with a mocked endpoint.

Describe the bug

To mock requests made using $fetch and useFetch, I expect to be able to use a utility like msw.

Unfortunately, this doesn't seem to work in combination with @nuxt/test-utils.

I've created a reproduction where you can see that globalThis.fetch is mocked just fine, but useFetch or fetch is not:

https://stackblitz.com/~/github.com/rinux55/nuxt-fetch

Any help with this would be greatly appreciated.

Additional context

No response

Logs

No response

@rinux55
Copy link
Author

rinux55 commented Mar 22, 2024

Linking unjs/ofetch#295 here as well

@ExEr7um
Copy link
Contributor

ExEr7um commented Apr 14, 2024

As a workaround you can try to use registerEndpoint function.

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

2 participants