Built-in Test Context in Vitest

From the Vitest cheat sheet ยท Test Context & Fixtures ยท verified Nov 2026

Built-in Test Context

task, expect, skip, signal, annotate, and per-test hooks from the first test argument

typescript
test('context', ({ task, expect, skip, signal, onTestFinished }) => {
  console.log(task.name)                       // 'context'
  skip(!process.env.API_KEY, 'needs API_KEY')
  onTestFinished(() => cleanup())
})
๐Ÿ“Œ The first test argument is the context; destructure what you need
๐Ÿ’ก Use the context expect in concurrent tests for correct snapshots
โšก Pass signal to fetch so a timed-out test stops its request
๐Ÿ” v5 also puts a bench fixture on the context for benchmarks
test-contexttasksignal

Continue with Vitest

Save the full cheat sheet or work through every related task.

More Vitest tasks

Back to the full Vitest cheat sheet