Skip to content
masterclass Buddy

Vitest · Method

vi.stubGlobal

vi.stubGlobal replaces a global variable during a test. Use vi.unstubAllGlobals or the unstubGlobals setting to restore it.

Last updated

Syntax

function stubGlobal(name: string | number | symbol, value: unknown): Vitest

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

Subscribe
  • vi.unstubAllGlobals
  • unstubGlobals
  • globalThis
  • vi.fn

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