Fixture Scopes, Overrides & Object Syntax in Vitest

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

Fixture Scopes, Overrides & Object Syntax

Share fixtures per file or worker, override them per suite, or use the Playwright-style object API

typescript
const test = base
  .extend('port', { scope: 'worker' }, 5432)                        // per worker
  .extend('db', { scope: 'file' }, ({ port }) => connect(port))     // per file
  .extend('role', 'viewer')                                         // per test

describe('admins', () => {
  test.override({ role: 'admin' })   // this suite only
})
๐Ÿ” Scopes are test (default), file and worker; wider ones are shared
๐Ÿ“Œ test.override must be called at the top of a describe block
๐ŸŽญ The object syntax matches Playwright fixtures; see the Playwright sheet
โš ๏ธ In non-isolated runs a worker fixture override leaks to later files
fixturesscopetest.override

Continue with Vitest

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

More Vitest tasks

Back to the full Vitest cheat sheet