-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
feat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
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 when vi.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
- Run
npm installto install dependencies. - Run
npm run test:browserto start the test in the browser. - In
components/index.test.ts, MSW fails to mock the GraphQL queries. However, when pressing therefetch pokemonbutton in the browser, the mock works as expected. - Comment out the
vi.mocksection in the test file, kill the running task in the terminal, and rerunnpm run test:browser
vi.mock("anyModuleToMock", () => ({
default: {
key: "value",
},
}));
- Now, MSW successfully mocks the GraphQL queries without the
vi.mock.
System Info
System:
OS: macOS 14.5
CPU: (8) arm64 Apple M2
Memory: 70.97 MB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.12.2 - ~/.nodebrew/current/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 10.5.0 - ~/.nodebrew/current/bin/npm
Watchman: 2024.04.15.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 130.0.6723.58
Safari: 17.5
npmPackages:
@vitest/browser: ^2.1.3 => 2.1.3
vitest: ^2.1.3 => 2.1.3Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)