Skip to content

Commit

Permalink
docs: Update common-errors to include dynamic import aliases (#6227)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek authored Aug 9, 2024
1 parent d795112 commit 5d54203
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/api/vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ vi.mock(import('./path/to/module.js'), async (importOriginal) => {

Under the hood, Vitest still operates on a string and not a module object.

If you are using TypeScript with `paths` aliases configured in `tsconfig.json` however, the compiler won't be able to correctly resolve import types.
In order to make it work, make sure to replace all aliased imports, with their corresponding relative paths.
Eg. use `import('./path/to/module.js')` instead of `import('@/module')`.

::: warning
`vi.mock` is hoisted (in other words, _moved_) to **top of the file**. It means that whenever you write it (be it inside `beforeEach` or `test`), it will actually be called before that.

Expand Down

0 comments on commit 5d54203

Please sign in to comment.