This repository is a reproduction of the issue with vi.mock
in Zimic.
-
Clone this repository:
git clone [email protected]:diego-aquino/zimic-vi-mock-issue.git
-
Install dependencies:
pnpm install
-
Run the tests:
pnpm test
The file example.test.ts
contains one test case using a simple interceptor to mock a fetch
request. Line 4 contains a vi.mock
call. The test case should pass, but it fails with the error below. Commenting the
vi.mock
call makes the test pass.
stderr | tests/example.test.ts
[MSW] The currently registered Service Worker has been generated by a different version of MSW (2.4.3) and may not be fully compatible with the installed version.
It's recommended you update your worker script by running this command:
• npx msw init <PUBLIC_DIR>
You can also automate this process and make the worker script update automatically upon the library installations. Read more: https://mswjs.io/docs/cli/init.
❯ tests/example.test.ts (1)
❯ Example tests (1)
× example
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL tests/example.test.ts > Example tests > example
TypeError: Failed to fetch
❯ tests/example.test.ts:38:27
36| });
37|
38| const response = await fetch('http://localhost:3000/example');
| ^
39| expect(response.status).toBe(200);