Writing Browser Tests in Vitest

From the Vitest cheat sheet · Browser Mode · verified Nov 2026

Writing Browser Tests

Render components, query with locators, interact, and assert with expect.element

typescript
import { expect, test } from 'vitest'
import { page } from 'vitest/browser'
import { render } from 'vitest-browser-react'

test('increments', async () => {
  const screen = await render(<Counter />)
  await screen.getByRole('button', { name: 'Increment' }).click()
  await expect.element(screen.getByText('Count is 1')).toBeVisible()
})
📌 Always await expect.element; it polls until the element matches
⚠️ v5 locators match text exactly; pass { exact: false } for partial
💡 userEvent triggers real browser events, not simulated ones
🎭 Need full E2E across pages and tabs? See the Playwright sheet
browser-modelocatorscomponent-testingreact

Continue with Vitest

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

More Vitest tasks

Back to the full Vitest cheat sheet