-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
MSW fails to intercept GraphQL queries when using vi.mock in Browser Mode #6766
Comments
Hi, @ytoshiki. Thanks for reporting this. We've looked into the issue, and the setup and usage on your side look correct. There was a bug in MSW that prevented it from correctly forwarding the requests from the test frame to the respective worker instance (the one you create in tests). Just upgrading msw to 2.5.0 in Vitest should fix the problem. @sheremet-va also proposed moving the Vitest's worker to the test frame, which will also eliminate the problem by keeping all workers in a single context. |
I upgraded msw to 2.5.0, and it worked perfectly! |
Thank you for addressing the bug. However, after upgrading to version 2.1.4, MSW is once again unable to intercept requests when using |
I added an example to catch this regression in the future: https://github.com/vitest-tests/browser-examples/tree/main/examples/vue-msw-graphql You can run it with pnpm install
cd examples/vue-msw-graphql
pnpm test |
I am facing a similar issue with When there are no Repro: |
I am also facing an issue with this, I filed an issue in MSW a few weeks back and it looks like its failing to intercept ALL requests for me, not just graphql requests. Reproduction is in the linked issue. |
I also encountered this issue, here is the minimal reproduction I tried: https://github.com/e7h4n/msw-vitest-failure/blob/main/index.test.ts |
Describe the bug
I am encountering an issue where MSW is unable to intercept GraphQL queries when using
vi.mock
from Vitest in my test setup.Regardless of which module is being mocked using
vi.mock
, MSW cannot intercept the requests whenvi.mock
is active.Reproduction
A minimal reproduction of the issue can be found here. https://github.com/ytoshiki/repro-msw-vitest-browser
Steps To Reproduce
npm install
to install dependencies.npm run test:browser
to start the test in the browser.components/index.test.ts
, MSW fails to mock the GraphQL queries. However, when pressing therefetch pokemon
button in the browser, the mock works as expected.vi.mock
section in the test file, kill the running task in the terminal, and rerunnpm run test:browser
vi.mock
.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: