Unable to use with `msw` to mock requests
rinux55 opened this issue · 6 comments
rinux55 commented
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: npm@10.2.4
- 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 commented
Linking unjs/ofetch#295 here as well
ExEr7um commented
As a workaround you can try to use registerEndpoint
function.