react-testing
Installation
SKILL.md
React Testing
Priority: P2 (MAINTENANCE)
Reliable tests focusing on user behavior.
Implementation Guidelines
- Standards: Use React Testing Library (RTL) with Vitest or Jest. Follow the Arrange-Act-Assert (AAA) pattern.
- Selection: Prefer
getByRole/findByRoleto test accessibility. Usedata-testidonly as a fallback for complex UI. - Interactions: Use
userEvent(async) instead offireEventto better simulate browser events (e.g.,await user.click(element)). - Asynchrony: Use
await screen.findBy*for elements that appear later. UsewaitFor(() => ...)for complex non-element updates. - Networking: Mock all API calls with Mock Service Worker (MSW). Never call real APIs in unit/integration tests.
- Architecture: Test behavior, not implementation. Avoid checking internal
stateorprops. Ensure 100% of P0 flows are covered. - Mocks: Mock expensive third-party libraries (e.g.,
framer-motion,react-router) or heavy assets to speed up tests. - Visuals: Use Snapshot testing sparingly for stable, small UI components. Manual a11y checks with
jest-axe.