Waiting for Conditions in Vitest
From the Vitest cheat sheet · Async Testing · verified Nov 2026
Waiting for Conditions
Retry assertions or callbacks until async state settles
typescript
await expect.poll(() => getStatus()).toBe('ready')
await vi.waitFor(() => {
expect(server.isReady).toBe(true)
})
const el = await vi.waitUntil(() => document.querySelector('.toast'))💡 expect.poll for assertions, vi.waitFor for setup code that throws
📌 vi.waitUntil fails right away if the callback throws
⚡ All three auto-advance fake timers between attempts
⚠️ expect.poll does not support snapshots, toThrow or .resolves
waitForwaitUntilpoll
Continue with Vitest
Save the full cheat sheet or work through every related task.