Skip to content
masterclass Buddy

Jest · Function

jest.spyOn

jest.spyOn watches an existing object method and records its calls. It calls the original method by default, but you can replace that behavior and restore the spy later.

Last updated

Since
22.1.0

Syntax

jest.spyOn(object, methodName)
jest.spyOn(object, methodName, accessType?)

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

Subscribe
  • jest.fn
  • jest.restoreAllMocks
  • jest.replaceProperty
  • mockFn.mockImplementation
  • mockFn.mockRestore

Source: The Jest Object · Jest. Checked 2026-11-03.