mockreset jest code example
Example: jest mockclear
test("mockFn.mockClear", () => {
const mockFn = jest.fn().mockImplementation(() => 42);
const MockClass = jest.fn();
new MockClass();
expect(mockFn()).toBe(42);
expect(mockFn.mock.calls).toHaveLength(1);
expect(MockClass.mock.instances).toHaveLength(1);
new MockClass();
expect(mockFn()).toBe(42);
expect(mockFn.mock.calls).toHaveLength(2);
expect(MockClass.mock.instances).toHaveLength(2);
mockFn.mockClear();
MockClass.mockClear();
new MockClass();
expect(mockFn()).toBe(42);
expect(mockFn.mock.calls).toHaveLength(1);
expect(MockClass.mock.instances).toHaveLength(1);
});