jest 🃏

My new preferred testing framework (2020 edition).

Mock clearing/resetting/restoring WTF

There are three options to undo things in Jest mocks:

  • m.mockClear(): remove all mock data (eg: m.mock.calls and m.mock.instances)
  • m.mockReset(): clear the mock (m.mockClear()) and removes mocked return values and implementations
  • m.mockRestore(): reset the mock (m.mockReset()) and restore the original (non-mocked) implementation

PS: the m variable on the examples below is a mock function:

const m = jest.fn(() => true);

results matching ""

    No results matching ""