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 mocking modules using vi.mock (or vi.doMock), if the module is replaced implicitly, a subsequent call to vi.unmock (or vi.doUnmock) will not unmock the module.
import{vi,afterEach,test,expect}from'vitest'afterEach(()=>{vi.doUnmock('./dependency')})test('mock by imitating the actual module',async()=>{vi.doMock('./dependency')constdependency=awaitimport('./dependency')expect(vi.mocked(dependency.doSomething).mock).toBeDefined()})test('verify module is not mocked after call to doUnmock',async()=>{constdependency=awaitimport('./dependency')expect(vi.mocked(dependency.doSomething).mock).not.toBeDefined()})
I believe this to be a bug, because if you provide an explicit replacement via the second argument to vi.mock, instead of relying on the module imitation logic, the call to unmock will successfully remove the mock.
Describe the bug
When mocking modules using
vi.mock
(orvi.doMock
), if the module is replaced implicitly, a subsequent call tovi.unmock
(orvi.doUnmock
) will not unmock the module.I believe this to be a bug, because if you provide an explicit replacement via the second argument to
vi.mock
, instead of relying on the module imitation logic, the call tounmock
will successfully remove the mock.Reproduction
See mcous/vitest-unmock-bug
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: