Open rinux55 opened 3 months ago
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.
app.test.ts
test/setup.ts
test/server.ts
msw
To mock requests made using $fetch and useFetch, I expect to be able to use a utility like msw.
$fetch
useFetch
Unfortunately, this doesn't seem to work in combination with @nuxt/test-utils.
@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:
globalThis.fetch
fetch
Any help with this would be greatly appreciated.
No response
Linking https://github.com/unjs/ofetch/issues/295 here as well
As a workaround you can try to use registerEndpoint function.
registerEndpoint
Environment
Build Modules: -
Reproduction
https://stackblitz.com/~/github.com/rinux55/nuxt-fetch
See
app.test.ts
. In thetest/setup.ts
andtest/server.ts
there is anmsw
server being set up with a mocked endpoint.Describe the bug
To mock requests made using
$fetch
anduseFetch
, I expect to be able to use a utility likemsw
.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, butuseFetch
orfetch
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