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
When using vi.spyOn() to create function mocks, the spy.mockRestore(), vi.mockRestoreAllMocks() doesn't actually restore the original descriptor of the spied-on object. This can lead to tests being written without ensuring that a method was already mocked, and deviates from Jest's equivalent behavior.
This is technically intended behavior. I am not sure if it's the right behavior, but removing a spy breaks module mocking as far as I remember. If someone has time to investigate the consequences of this change, be my guest.
Describe the bug
When using
vi.spyOn()
to create function mocks, thespy.mockRestore()
,vi.mockRestoreAllMocks()
doesn't actually restore the original descriptor of the spied-on object. This can lead to tests being written without ensuring that a method was already mocked, and deviates from Jest's equivalent behavior.Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-csdybj?file=test%2Fbasic.test.ts
System Info
envinfo doesn't seem to work with my project's setup (Yarn 3 monorepo), here are my vitest versions:
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: