Testing pyramid
- Unit tests: pure functions and small components
- Integration tests: component behavior with dependencies
- End-to-end tests: critical user journeys
Recommended tools
- Vitest or Jest
- React Testing Library
- Playwright or Cypress
Component test example
tsx
import { render, screen, fireEvent } from '@testing-library/react';
render(<Counter />);
fireEvent.click(screen.getByRole('button', { name: /increment/i }));
expect(screen.getByText('1')).toBeInTheDocument();Testing best practices
- Test behavior, not implementation details
- Prefer accessible queries (
getByRole) - Cover critical business flows first
Next, we will handle runtime UI failures with error boundaries.