Skip to content
masterclass Buddy

Vitest · Module

resolves

vi.mock replaces imports from a module with a mock. The call is hoisted, so it runs before imports.

Last updated

Syntax

function mock(path: string, factory?: MockOptions | MockFactory<unknown>): void
function mock<T>(module: Promise<T>, factory?: MockOptions | MockFactory<T>): void

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

Subscribe
  • vi.doMock
  • vi.hoisted
  • __mocks__
  • vi.importActual
  • vi.importMock

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