Skip to content

Commit

Permalink
fix(mocker)!: don't restore mock to the original if module is mocked (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jun 6, 2023
1 parent 821126f commit c1004e1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/mocks/test/automocking.spec.ts
Expand Up @@ -56,8 +56,8 @@ test('automock properly restores mock', async () => {
log.warn()
}).not.toThrow()

expect(moduleWithSymbol[methodSymbol]()).toBe('hello')
expect(moduleWithSymbol.warn()).toBe('hello')
expect(moduleWithSymbol[methodSymbol]()).toBe(undefined)
expect(moduleWithSymbol.warn()).toBe(undefined)

expect(log.warn).toHaveProperty('mockImplementation')
})
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/mocker.ts
Expand Up @@ -296,7 +296,7 @@ export class VitestMocker {
const mock = spyOn(newContainer, property).mockImplementation(() => undefined)
mock.mockRestore = () => {
mock.mockReset()
mock.mockImplementation(undefined!)
mock.mockImplementation(() => undefined)
return mock
}
// tinyspy retains length, but jest doesn't.
Expand Down
3 changes: 2 additions & 1 deletion test/core/test/mocked-no-mocks.test.ts
Expand Up @@ -15,6 +15,7 @@ test('mocking several modules work', () => {

mockedB()

expect(mockedA).toHaveBeenCalledTimes(2)
// mockedA is not called because mockedB is restored to be undefined
expect(mockedA).toHaveBeenCalledTimes(1)
expect(mockedB).toHaveBeenCalledTimes(1)
})

0 comments on commit c1004e1

Please sign in to comment.