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
Let's say I have a function main that calls a function foobar. When testing main, I would like to mock foobar and have the mock implementation in a separate file.
In my test file, if I import the file with the mock implementation BEFORE the file where the function main is, everything works fine.
However if I import the file with the mock implementation AFTER the file where the function main is,vitest complains with the following hoisting error:
Notes: this example might be silly for functions but this pattern comes in handy in different context when trying to mock components and organize code in several files.
Describe the bug
The stackblitz below illustrates the issue.
Let's say I have a function
main
that calls a functionfoobar
. When testingmain
, I would like to mockfoobar
and have the mock implementation in a separate file.In my test file, if I import the file with the mock implementation BEFORE the file where the function
main
is, everything works fine.However if I import the file with the mock implementation AFTER the file where the function
main
is,vitest
complains with the following hoisting error:Notes: this example might be silly for functions but this pattern comes in handy in different context when trying to mock components and organize code in several files.
Reproduction
https://stackblitz.com/edit/vitejs-vite-q8pc8e?file=main.test.js&view=editor
Simply run the command
npm exec vitest
to see the issue.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: