Skip to content
masterclass Buddy

Vitest · Type Alias

MockInstance

Vitest MockInstance objects let tests inspect calls and control mock functions, spies, and mocked classes. Use vi.fn for a new mock and vi.spyOn for an existing object method.

Last updated

Syntax

vi.fn(implementation?)
vi.spyOn(object, method)
vi.mock(path, factory?)

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

Subscribe
  • vi.fn
  • vi.spyOn
  • vi.mock
  • vi.hoisted
  • mock.calls
  • mock.instances
  • toHaveBeenCalled

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