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
vi.mock('a-vitest-test-modulea',()=>{console.log('INITIALIZE MOCK');return{default: vi.fn().mockReturnValue('I am mocked'),};});
then the mock gets initialised multiple times - one time when my actual source file imports it and the other when my test imports it so I can make assertions - which makes it impossible to run e.g. toBeCalledTimes assertions. This is working in Jest as expected.
Note: when modifying the module to import a string rather than a variable, the behavior is expected:
exportdefaultasync()=>{// this way it worksreturn(awaitimport('a-vitest-test-modulea')).default();// this way it doesn'tconstid='a-vitest-test-modulea';return(awaitimport(id)).default();};
Describe the bug
Given a module that imports a package dynamically, e.g.:
If I define
a-vitest-test-modulea
as a mock via:then the mock gets initialised multiple times - one time when my actual source file imports it and the other when my test imports it so I can make assertions - which makes it impossible to run e.g.
toBeCalledTimes
assertions. This is working in Jest as expected.Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-payj4m?file=src%2Findex.ts,test%2Fbasic.test.ts&initialPath=__vitest__
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: