Skip to content
masterclass Buddy

Jest · Function

jest.mock

jest.fn() creates a mock function, also called a spy. It records how code calls the function and lets a test control its implementation or returned values.

Last updated

Syntax

jest.fn(implementation?)

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • jest.spyOn()
  • mockFn.mock.calls
  • mockFn.mock.results
  • mockFn.mock.instances
  • mockFn.mock.contexts
  • mockFn.mockClear()
  • mockFn.mockReset()
  • mockFn.mockRestore()

Source: Mock Functions · Jest. Checked 2026-11-03.