ecc-react-testing

Write behavior-focused React component, hook, and accessibility tests with MSW network mocking.

Updated Apr 18, 2025
One-click install
npx skills add https://github.com/adriancodes/dotfiles --skill ecc-react-testing-adriancodes
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ecc-react-testing
Source: https://github.com/adriancodes/dotfiles/tree/main/dot_agents/skills/ecc-react-testing
Command: npx skills add https://github.com/adriancodes/dotfiles --skill ecc-react-testing-adriancodes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing React tests that assert on implementation details leads to brittle suites that break on refactors and miss real user-facing bugs. This Skill provides patterns for behavior-focused testing with React Testing Library, Vitest or Jest, and MSW so tests reflect what users actually see and do. ## Core Features & Use Cases - Behavior-Focused Component Tests: Query by role and label, interact with userEvent, and assert visible output instead of internal state or render counts. - Network Mocking with MSW: Mock HTTP at the network layer with per-test handler overrides and loud failures on unmocked requests. - Hook, Accessibility, and Async Patterns: Test custom hooks with renderHook and act, run axe accessibility checks, and handle async UI with findBy and waitFor. - Use Case: When adding coverage to a legacy form component, wrap it in production-like providers, mock its API calls with MSW, submit via userEvent, and assert the success message appears. ## Quick Start Write a React Testing Library test for my UserForm component that mocks the save API with MSW and asserts the success message appears after submission.

Frequently Asked Questions about ecc-react-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test React components with React Testing Library?▼

Render the component with its production providers, query elements by role or label, interact using userEvent, and assert on visible output or observable side effects. Avoid inspecting component state, props, or render counts.

How do I mock API requests in React tests with MSW?▼

Set up an MSW server with request handlers in your test setup file, then override handlers per test with server.use for error or edge cases. Configure onUnhandledRequest to error so unmocked requests fail loudly.

Vitest vs Jest for React testing: which should I use?▼

Vitest suits Vite, Remix, and modern ESM setups with faster execution and a Jest-compatible API. Jest remains the default for Next.js, CRA, and established repositories. Pick one runner rather than mixing both.

How do I test custom React hooks with renderHook?▼

Use renderHook from React Testing Library, wrap state-changing calls in act, and test only through the hook's public API. For hooks using context like React Query, pass a wrapper with a QueryClient created once per test.

When should I use Playwright instead of JSDOM for component tests?▼

Use Playwright Component Testing when tests need real layout, browser animations, scrolling, drag-and-drop, iframes, or downloads, since JSDOM cannot render these. Keep hooks, forms, and presentational components in RTL.

Why are snapshot tests discouraged for React components?▼

Snapshots of rendered DOM break on every styling change, get rubber-stamped in review, and test implementation details rather than behavior. Use visual regression tools like Playwright screenshots or Chromatic for appearance checks instead.