Loading...
Loading...
Testing Library for React 19 - render, screen, userEvent, waitFor, Suspense. Use when writing tests for React components with Vitest.
npx skill4agent add fusengine/agents react-testingTeamCreate| Feature | Benefit |
|---|---|
| User-centric | Tests what users see |
| Accessible queries | Encourages a11y markup |
| No implementation details | Resilient to refactoring |
| Vitest integration | 10-20x faster than Jest |
getByRolesetTimeout| Topic | Reference |
|---|---|
| Setup & installation | |
| Query priority | |
| User interactions | |
| Async patterns | |
| API mocking | |
| React 19 hooks | |
| Accessibility | |
| Custom hooks | |
| Vitest config | |
| Mocking patterns | |
| Template | Use Case |
|---|---|
| Vitest + RTL + MSW config |
| Simple component tests |
| Loading/error/success |
| Forms + useActionState |
| Custom hook tests |
| MSW integration tests |
| Suspense + use() |
| Error boundary tests |
| axe-core a11y audit |
| Pattern | Reason | Alternative |
|---|---|---|
| Not realistic | |
| Flaky | |
| Not accessible | |
| Direct fetch mocking | Hard to maintain | MSW |
Empty | No assertion | Add |
npm install -D vitest @testing-library/react \
@testing-library/user-event @testing-library/jest-dom \
jsdom mswtemplates/basic-setup.mdimport { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
test('button click works', async () => {
const user = userEvent.setup()
render(<Button onClick={fn}>Click</Button>)
await user.click(screen.getByRole('button'))
expect(fn).toHaveBeenCalled()
})templates/component-basic.mdgetByRolegetByLabelTextgetByTextgetByTestId// Preferred: findBy
await screen.findByText('Loaded')
// Alternative: waitFor
await waitFor(() => expect(...).toBeInTheDocument())templates/component-async.mdconst user = userEvent.setup()
await user.click(button)
await user.type(input, 'text')references/user-events.md