Skip to content
masterclass Buddy

Vitest · Function

vi.fn

vi.fn creates a mock function. It can record calls and use a real or custom implementation.

Last updated

Syntax

function fn(fn?: Procedure | Constructable): Mock

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

Subscribe
  • vi.spyOn
  • mockClear
  • mockImplementation
  • mockImplementationOnce
  • mockReset
  • mockRestore
  • mockReturnValue
  • mockReturnValueOnce

Source: Vi | Vitest. Checked 2026-11-03.