Skip to content
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

When restoreMocks is true functions in auto-mocked files are being restored to their original implementation #3503

Closed
6 tasks done
HristoKolev opened this issue Jun 3, 2023 · 1 comment · Fixed by #3518

Comments

@HristoKolev
Copy link

Describe the bug

When you call vi.restoreAllMocks(); or have restoreMocks set to true this restores functions in modules that are mocked like this vi.mock('./multiply');. to their original implementation.

That behavior is not documented here https://vitest.dev/guide/mocking.html#automocking-algorithm and is possibly not intended.

This certainly breaks compatibility with jest where restoring all mocks doesn't touch auto-generated modules.

Reproduction

https://stackblitz.com/edit/node-rnge8j?file=mock.test.ts

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (32) x64 AMD Ryzen 9 7950X 16-Core Processor
    Memory: 15.75 GB / 31.16 GB
  Binaries:
    Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 9.2.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.1702.0), Chromium (113.0.1774.57)
    Internet Explorer: 11.0.22621.1

Used Package Manager

npm

Validations

@stackblitz
Copy link

stackblitz bot commented Jun 3, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants