Skip to content
masterclass Buddy

Vitest · Method

vi.stubEnv

vi.stubEnv temporarily changes an environment variable in process.env and import.meta.env. Use vi.unstubAllEnvs to restore values changed with this helper.

Last updated

Syntax

function stubEnv<T extends string>(name: T, value: T extends 'PROD' | 'DEV' | 'SSR' ? boolean : string | undefined): Vitest

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

Subscribe
  • vi.unstubAllEnvs
  • import.meta.env
  • process.env
  • unstubEnvs

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