Browser mode: cannot overwrite request handler when MSW is initialized in setup file #6690
Closed
6 tasks done
Labels
feat: browser
Issues and PRs related to the browser runner
p3-minor-bug
An edge case that only affects very specific usage (priority)
Describe the bug
I have a
HelloWorld.tsx
component that displays a random joke using the https://api.chucknorris.io/jokes/random API (sorry about that), which I'm mocking using MSW:using the MSW worker:
MSW is initialized in
vitest-setup.ts
:🐛 When I run the tests, the test cases that use default handlers pass, but the ones that override them fail, eg:
The text from the response is not found (the one from the default mock is here though), which seems to indicate that the override is not working.
However, if I move the initialization from the setup file to the test file itself, then all tests pass 🤔
Refs:
Reproduction
The issue can be reproduced at https://github.com/foxaltus/vitest-browser-mode-msw.
The workaround can be seen here: https://github.com/foxaltus/vitest-browser-mode-msw/compare/workaround
Use
pnpm run test
script.System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: