-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vi.mock
ignored if module is imported in setup file
#1450
Comments
I found the problem, but I am not sure it's possible to fix without losing performance. For now, you can call |
Thanks, I have added |
Module was already evaluated and cached with code that you provided in setup, so when it is imported next time, it uses this cached version. I don't think there is a good way for us to clear that cache automatically, so you need to use |
Describe the bug
Registration of
vi.mock
on a module will not work if that module is imported in a file added to thesetupFiles
array invite.config.ts
.Use case
We use Vue 3 with global component registration (this is needed because of the way our CMS works). To accomplish this in our tests, we register these components in
vitest.setup.ts
to the@vue/test-utils
config as the example below.This causes the mocks set on the imports of these components to be ignored. Although this is our use case, this issue is unrelated to Vue. See the minimal reproduction for more details.
Reproduction
Here is a minimal repo: https://stackblitz.com/edit/vitest-dev-vitest-etmse4?file=vitest.setup.ts
In
test/foo.test.ts
a mock is used. This fails, unless I remove the only line invitest.setup.ts
.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: