Skip to content
masterclass Buddy

Vitest · Method

vi.mocked

vi.mocked is a TypeScript helper that marks an existing value as mocked for type checking. It returns the same value at runtime and supports shallow, deep, and partial mock typing.

Last updated

Syntax

vi.mocked<T>(object: T, deep?: boolean): MaybeMockedDeep<T>
vi.mocked<T>(object: T, options?: { partial?: boolean; deep?: boolean }): MaybePartiallyMockedDeep<T>

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

Subscribe
  • vi.mock
  • vi.fn
  • vi.importMock

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