Performance: React Testing Library integration
MEDIUM IMPACT
This affects the development and testing workflow speed, indirectly impacting how quickly UI bugs are caught and fixed, which can improve user experience by reducing runtime errors.
import { render, screen } from '@testing-library/react'; import MyComponent from '../MyComponent'; test('renders component with accessible role', () => { render(<MyComponent />); expect(screen.getByRole('main')).toBeInTheDocument(); });
import { render } from '@testing-library/react'; import MyComponent from '../MyComponent'; test('renders component', () => { const { container } = render(<MyComponent />); expect(container.querySelector('div')).toBeInTheDocument(); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using container queries in tests | High DOM traversal | N/A (test environment) | N/A (test environment) | [X] Bad |
| Using accessible queries (getByRole, getByText) | Minimal DOM traversal | N/A (test environment) | N/A (test environment) | [OK] Good |