async/await, resolves & rejects in Vitest

From the Vitest cheat sheet · Async Testing · verified Nov 2026

async/await, resolves & rejects

Await async code and assert on promises the Vitest 5 way

typescript
test('loads a user', async () => {
  const user = await getUser(1)
  expect(user.name).toBe('Ada')
})

await expect(getUser(1)).resolves.toMatchObject({ name: 'Ada' })
await expect(getUser(-1)).rejects.toThrow('not found')
📌 v5 fails the test if a resolves/rejects assertion isn't awaited
⚠️ Vitest has no done callback; return or await a Promise instead
💡 The context signal aborts on timeout, bail or Ctrl+C
🟢 A rejected promise from the test function fails the test
asyncpromisesresolvesrejects

Continue with Vitest

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

More Vitest tasks

Back to the full Vitest cheat sheet