-
-
Notifications
You must be signed in to change notification settings - Fork 537
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
Browser: worker not mocking requests when vi.mock
present
#2398
Comments
downloadData
, only in browser mode.
Looking at more of my tests, it seems like the real problem is that my handlers are not properly intercepting/mocking the network calls. It appears to fire the request and match correctly, but not mock properly and end up somehow bypassing? Am I configuring the Please take a look at the sample repo so I can fix it and contribute it to an msw/example browser mode setup. Thank you |
I am also getting this at some places in my console when I run my tests...
i did not have any issues with any of the mocking when I was using the |
I'm hitting a seemingly similar issue while trying to use msw with vitest browser mode. My request handlers are being called, but ultimately msw is bypassing all requests, so all my mocked requests are resulting in 404 responses. |
I just realized that vitest browser is setting up its own msw request handler when |
@bdpartridge is it? Take a look at my reproduction. I don't use |
@charlieforward9 You're right. It looks like yours is a different issue. I tried out your reproduction and noticed that the
…I see the mocked 200 response for Anyway, sorry for adding noise to this thread. Good luck resolving this. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
vi.mock
present in beforeAll
vi.mock
present in beforeAll
vi.mock
present
@bdpartridge seems to be right
The reason it wasnt working on my repro without If you think this isnt a problem with msw, have you opened an issue with vitest yet? Any workarounds other than commenting out |
I also encountered this issue, here is the minimal reproduction I tried: https://github.com/e7h4n/msw-vitest-failure/blob/main/index.test.ts |
Same here, commenting out all the |
Hi, everyone. Thanks for sharing your details and reproduction repos! Much appreciated. This one is most likely on MSW's side, but it needs proper investigation before we can know for certain. Since Vitest also uses an MSW worker under the hood for How you can help
|
Without a
With a
I have an error when executing the function
|
It looks like vitest runs its own worker setup when Interestingly, the For now, I'm working around this by specifying aliases in the vitest config. That works okay for my use case since none of my module mocks are test-specific at the moment. |
Prerequisites
Environment check
msw
versionBrowsers
Chromium (Chrome, Brave, etc.)
Reproduction repository
https://github.com/Agriculture-Intelligence/msw-vitest-browser-issue
Reproduction steps
aws-amplify
,vitest
,msw
vitest
andmsw
to support browser-based testing/mockingdownloadData
command fromaws-amplify/storage
moduleNETWORK ERR
Current behavior
Functional in development and node/jsdom testing, when configuration is changed to browser-based, fails.
Expected behavior
I expect the browser based mocking to work exactly the same as node based testing.
The text was updated successfully, but these errors were encountered: