Skip to content
masterclass Buddy

Vitest · Function

beforeEach

beforeEach runs setup code before every test in the current file or suite. It can wait for async setup and can return cleanup code.

Last updated

Syntax

function beforeEach(body: (context: TestContext) => unknown, timeout?: number): void

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

Subscribe
  • afterEach
  • beforeAll
  • afterAll
  • onTestFinished
  • test.extend
  • hookTimeout
  • describe

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