You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the test file starts with vi.mock(), then the module isn't mocked. Other vi.mock() after the first are not affected, even if they are right after the first one. This issue started with vitest 3.0.0, vitest<3 are not affected.
❯ npm install && npm run test:ui
up to date in 510ms
14 packages are looking for funding
run `npm fund` for details
> test:ui
> vitest --ui
DEV v3.0.5 /home/projects/vitest-dev-vitest-bqqlcrmh
UI started at http://localhost:51204/__vitest__/
stdout | src/bug.test.js > am i bugged?
{ first: [Function: first] }
{
second: [Function: second] {
getMockName: [Function (anonymous)],
mockName: [Function (anonymous)],
mockClear: [Function (anonymous)],
mockReset: [Function (anonymous)],
mockRestore: [Function (anonymous)],
getMockImplementation: [Function (anonymous)],
mockImplementation: [Function (anonymous)],
mockImplementationOnce: [Function (anonymous)],
withImplementation: [Function: withImplementation],
mockReturnThis: [Function (anonymous)],
mockReturnValue: [Function (anonymous)],
mockReturnValueOnce: [Function (anonymous)],
mockResolvedValue: [Function (anonymous)],
mockResolvedValueOnce: [Function (anonymous)],
mockRejectedValue: [Function (anonymous)],
mockRejectedValueOnce: [Function (anonymous)]
}
}
{
third: [Function: third] {
getMockName: [Function (anonymous)],
mockName: [Function (anonymous)],
mockClear: [Function (anonymous)],
mockReset: [Function (anonymous)],
mockRestore: [Function (anonymous)],
getMockImplementation: [Function (anonymous)],
mockImplementation: [Function (anonymous)],
mockImplementationOnce: [Function (anonymous)],
withImplementation: [Function: withImplementation],
mockReturnThis: [Function (anonymous)],
mockReturnValue: [Function (anonymous)],
mockReturnValueOnce: [Function (anonymous)],
mockResolvedValue: [Function (anonymous)],
mockResolvedValueOnce: [Function (anonymous)],
mockRejectedValue: [Function (anonymous)],
mockRejectedValueOnce: [Function (anonymous)]
}
}
❯ src/bug.test.js (1 test | 1 failed) 6ms
× am i bugged? 6ms
→ expected false to be true // Object.is equality
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL src/bug.test.js > am i bugged?
AssertionError: expected false to be true // Object.is equality
- Expected
+ Received
- true
+ false
❯ null.<anonymous> src/bug.test.js:16:42
14| expect(vi.isMockFunction(third.third)).toBe(true)
15| expect(vi.isMockFunction(second.second)).toBe(true);
16| expect(vi.isMockFunction(first.first)).toBe(true);
| ^
17| });
18|
❯ _0x6ed099/< ../../../blitz.7f809d15.js:40:25097
❯ _0x6ed099 ../../../blitz.7f809d15.js:40:25059
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Test Files 1 failed (1)
Tests 1 failed (1)
Start at 02:49:48
Duration 2.71s (transform 50ms, setup 0ms, collect 103ms, tests 5ms, environment 0ms, prepare 506ms)
FAIL Tests failed. Watching for file changes...
press h to show help, press q to quit
Having vi.mock manually at the top shouldn't be necessary since Vitest transforms in that way, but I think it's a bug if already moved ones are broken. It's possible that the difference is due to Vite 6's change on ssr transform.
Describe the bug
If the test file starts with vi.mock(), then the module isn't mocked. Other vi.mock() after the first are not affected, even if they are right after the first one. This issue started with vitest 3.0.0, vitest<3 are not affected.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-bqqlcrmh?file=src%2Fbug.test.js,src%2Fmockmefirst.js,src%2Fgood.test.js&initialPath=__vitest__/
By changing the order of the vi.mock() in bug.test.js, you can see in console.log that only the first one is not mocked each time.
In good.test.js i moved the vi.mock() after the imports and all of them are mocked properly.
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: