affaan-m avatar

React Testing

A strong foundation for testing React components the modern way: React Testing Library, Vitest or Jest, MSW for HTTP mocking, and axe for accessibility checks. The guide is opinionated in the right ways, prioritizing user-facing behavior over implementation details, accessible queries over test IDs, and userEvent over fireEvent. The MSW setup with onUnhandledRequest error is excellent for catching silent test passes. The custom hook testing section correctly warns about QueryClient instantiation gotchas. Light on the boundary between component tests and full E2E, but the query priority table and provider wrapping pattern alone will save you from common mistakes if you're migrating from Enzyme or setting up tests from scratch.

skills.sh installs
5.8K
GitHub stars
300.3K
last updated
Aug 21, 2026

Install

$ npx -y skills add affaan-m/ecc --skill react-testing --agent claude-code

Installs into .claude/skills of the current project.

Files

React Testing

Comprehensive React testing patterns for behavior-focused component tests, custom hook tests, accessibility assertions, and network-level mocking.

When to Activate

  • Writing tests for React components, custom hooks, or pages
  • Adding test coverage to legacy untested components
  • Migrating from Enzyme or class-component-era patterns to React Testing Library
  • Setting up Vitest or Jest for a new React project
  • Mocking HTTP requests in tests
  • Asserting accessibility violations
  • Deciding which tests belong in RTL vs Playwright Component Testing vs full E2E

Core Principle

Test what the user sees and does, not implementation details.

A test should:

  • Render the component with the same providers it has in production
  • Interact with it via accessible queries (role, label) and userEvent
  • Assert visible output and observable side effects (callback fired, request sent)

A test should NOT:

  • Inspect component state, props passed to children, or which hooks were called
  • Mock React itself or framework hooks
  • Assert on the number of renders or DOM structure beyond what affects users

Library Choice

Sponsors

Details

Repository
github.com/affaan-m/ecc
Categories
Frontend Development, Testing & QA, Documentation, Productivity & Planning, Design & UI/UX
First seen
Jul 14, 2026

More from affaan-m/ecc

All 263
1affaan-m avatarfrontend-a11yaffaan-m/eccAccessibility patterns for React and Next.js — semantic HTML, ARIA attributes, form labeling, keyboard navigation, focus management, and screen reader support. 5.8Kskills.sh installs
2jeffallan avatarreact-expertjeffallan/claude-skillsUse when building React 18+ applications in .jsx or .tsx files, Next.js App Router projects, or create-react-app setups. Creates components, implements custom h5.8Kskills.sh installs
3lobehub avatarreactlobehub/lobehubLobeHub React component conventions. Use when editing TSX UI, choosing base-ui vs @lobehub/ui vs antd, styling with antd-style, component boundaries, local stat5.7Kskills.sh installs
4affaan-m avatarangular-developeraffaan-m/eccGenerates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signal5.5Kskills.sh installs
5forcedotcom avatarexperience-ui-bundle-metadata-generateforcedotcom/sf-skillsUse this skill when adding a front-end React UI bundle to an existing project or configuring UI bundle metadata and config files. TRIGGER when: adding or scaffo5.3Kskills.sh installs
6forcedotcom avatarexperience-ui-bundle-app-coordinateforcedotcom/sf-skillsMUST activate when the user wants to build, create, or generate a React application, React app, web application, single-page application (SPA), or frontend appl5.3Kskills.sh installs