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 I try to mock a module imported by another module, by providing an alias as key, such as vi.mock('@module-alias'), the module is not mocked as expected.
If I provide the relative path as key, such as vi.mock('..src/MyModule'), the module is mocked as expected.
// MyModule.testimport{MyModule}from'@/MyModule';import{vi,describe,it,expect}from'vitest';// Try with relative path ../src/MyInnerModule, it worksvi.mock('@/MyInnerModule',()=>{return{MyInnerModule: {key: 1,},};});describe('MyModule',()=>{it('should have key',()=>{expect.assertions(1);expect(MyModule.key).toBe(1);// Got undefined});});
This issue may be related to #2777 but it didn't solve my case.
Describe the bug
If I try to mock a module imported by another module, by providing an alias as key, such as
vi.mock('@module-alias')
, the module is not mocked as expected.If I provide the relative path as key, such as
vi.mock('..src/MyModule')
, the module is mocked as expected.This issue may be related to #2777 but it didn't solve my case.
Reproduction
Stackblitz, follow the instruction on line 4 to switch between non working and working
https://stackblitz.com/edit/vitest-dev-vitest-qj31uc?file=test/MyModule.test.ts
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: