aroundEach & aroundAll in Vitest

From the Vitest cheat sheet ยท Hooks & Lifecycle ยท verified Nov 2026

aroundEach & aroundAll

Wrap each test or a whole suite in a context such as a transaction or AsyncLocalStorage (4.1+)

typescript
import { aroundEach, test } from 'vitest'

// Every test runs inside the transaction callback
aroundEach(async (runTest) => {
  await db.transaction(runTest)
})

test('insert user', async () => {
  await db.insert({ name: 'Ada' })
})
๐Ÿ“Œ Added in 4.1; you must call runTest() or runSuite() or it fails
๐Ÿ’ก Use for AsyncLocalStorage, tracing spans, or DB transactions
โšก Plain setup/teardown? beforeEach with a cleanup return is simpler
๐Ÿ” The timeout applies separately to the before and after halves
aroundEacharoundAllhooks

Continue with Vitest

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

More Vitest tasks

Back to the full Vitest cheat sheet