Closed tobiasvoelke closed 3 years ago
Hi!
If I use mockClear() in combination with calledWith() it is still using the previous mocks:
mockClear()
calledWith()
import { mock, mockClear } from 'jest-mock-extended'; class Implementation { public doSomething(arg: string): string { return arg; } } describe('mockClear should clear calledWith', () => { let mockedClass = mock<Implementation>(); afterEach(() => { mockClear(mockedClass); }); it('should do sth', () => { mockedClass.doSomething.calledWith('hello').mockReturnValue('firstMock'); expect(mockedClass.doSomething('hello')).toEqual('firstMock'); }); it('should do sth2', () => { mockedClass.doSomething.calledWith('hello').mockReturnValue('secondMock'); expect(mockedClass.doSomething('hello')).toEqual('secondMock'); // fails with: // Error: expect(received).toEqual(expected) // deep equality // Expected: "secondMock" // Received: "firstMock" }); });
Workaround for now is to re-create the mock instead of calling mockClear()
Just realised I mixed up mockReset() and mockClear()
mockReset()
Hi!
If I use
mockClear()
in combination withcalledWith()
it is still using the previous mocks:Workaround for now is to re-create the mock instead of calling mockClear()