Skip to content
masterclass Buddy

Vitest · Method

vi.doMock

vi.doMock mocks a module without hoisting the call. The next dynamic import gets the mock, while earlier imports keep the original module.

Last updated

Syntax

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

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

Subscribe
  • vi.mock
  • vi.unmock
  • vi.hoisted
  • vi.importActual

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