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.