mswjs / msw

Seamless REST/GraphQL API mocking library for browser and Node.js.
https://mswjs.io
MIT License
15.67k stars 504 forks source link

Can't match the handler in tests in nuxt 3 app using useFetch composable #2215

Open andreimakushkin opened 1 month ago

andreimakushkin commented 1 month ago

Prerequisites

Environment check

Node.js version

v20.11.1

Reproduction repository

https://github.com/andreimakushkin/nuxt3-msw

Reproduction steps

I've created an Example vue component with test for it, the component use useFetch composable to call an API, but it doesn't work in test. The test just fails without any errors. MSW server doesn't intercept the call.

In order to run test, use command npm run test

await useFetch('/api/example'); // Doesn't match the handler
await useFetch('api/example'); // Matches the handler, but the app doesn't work

Current behavior

await useFetch('/api/example'); // Doesn't match the msw handler

Expected behavior

await useFetch('/api/example'); // Should match the msw handler

shunnNet commented 2 weeks ago

@andreimakushkin Hello, I have created a Nuxt module called nuxt-msw which should be able to address the issue you mentioned.