agentleFS
LeahyCCLeahyCC/claude-skills/skills/react-testing/SKILL.md

react-testing

Skill3 starsChanged 8 months agoMITView on GitHub

Writes and reviews React component tests with Vitest 5, React Testing Library 16, user-event 14, jest-dom 7, and MSW 3: query priority and accessible names, asserting absence, user-event setup, findBy and waitFor rules, act warnings, the Vitest fake-timer hang, cleanup without globals, jsdom gaps, custom renders with providers, renderHook, MSW handlers and error paths, vi.mock and next/navigation, and what async Server Components can and cannot do under RTL. Use when writing, fixing, or reviewing *.test.tsx files, when a test is flaky, hangs, or warns about act, or when the user mentions Testing Library, getByRole, userEvent, waitFor, or MSW. Not for generic false-green test review (gotchas), accessibility audits (wcag-accessibility), or React render speed (react-performance).

19 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use orch-pipeline, parallel-execution-optimizer and 9 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • renepfSkill

    orch-pipeline

    Shared orchestration engine for the orch-* skill family. Defines the gated Research-Plan-TDD-Review-Commit pipeline, the size classifier, the agent map, and the two human gates that the orch-* operation skills delegate to. Not usually invoked directly.

    Also in 4 projects that use this

  • marcusgollSkill

    parallel-execution-optimizer

    Identify and execute independent operations in parallel for 3-5x speedup. Auto-analyzes task dependencies, groups into batches, launches parallel Task() calls. Applies to /optimize (5 checks), /ship pre-flight (5 checks), /implement (task batching), /prototype (N screens). Auto-triggers when detecting multiple independent operations in a phase.

    Also in 5 projects that use this

  • ronmkrSkill

    vite-patterns

    Vite build tool patterns including config, plugins, HMR, env variables, proxy setup, SSR, library mode, dependency pre-bundling, and build optimization. Activate when working with vite.config.ts, Vite plugins, or Vite-based projects.

    Also in 6 projects that use this

  • RojiosSkill

    defi-amm-security

    Security checklist for Solidity AMM contracts, liquidity pools, and swap flows. Covers reentrancy, CEI ordering, donation or inflation attacks, oracle manipulation, slippage, admin controls, and integer math.

    Also in 5 projects that use this

  • renepfSkill

    prediction-market-oracle-research

    Research prediction markets as data sources or oracle signals for products, agents, dashboards, and corporate decision intelligence. Use for source-grounded analysis of market-implied probabilities, caveats, and integration patterns without investment advice.

    Also in 3 projects that use this

  • ronmkrSkill

    quarkus-security

    Quarkus Security best practices for authentication, authorization, JWT/OIDC, RBAC, input validation, CSRF, secrets management, and dependency security.

    Also in 4 projects that use this

  • +1 more from ronmkr
  • +2 more from renepf

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 19 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read the component, its existing tests, vitest.config.*, and the setup file.

    line 29
  2. Distinctive:

    Run the test. Then break the feature on purpose (comment out the handler, return the wrong value) and confirm the test fails.

    line 49

“Common” is measured: kept by at least 6 in 10 of the 19 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

React testing

Tests that fail when the feature breaks and pass when it works, whatever the internals look like. Find elements the way a user does, act the way a user does, and wait for what a user would see.

Query by role and name first. If you cannot, the component probably has an accessibility bug.

Mock the edges (network, clock, framework), never your own code.

Versions, source checks, and dates: SOURCES.md.

Procedure

  1. Read the component, its existing tests, vitest.config.*, and the setup file. Check the package versions; this skill assumes the stack in SOURCES.md.
  2. Pick what the user does and what they should see as a result. That pair is the test.
  3. Route by what the test needs, and load only that resource:
writing or fixing a test
      |
      +-- finding an element, asserting present or absent ...... queries.md
      |
      +-- clicking, typing, tabbing, uploading .................. user-events.md
      |
      +-- something appears later, a timer, an act warning ...... async.md
      |
      +-- config, cleanup, providers, hooks, jsdom crashes ...... setup.md
      |
      +-- fetch, vi.mock, next/navigation ...................... network-and-mocks.md
      |
      +-- async page, Server Function, useActionState ........... server-components.md
  1. Run the test. Then break the feature on purpose (comment out the handler, return the wrong value) and confirm the test fails. A test that still passes proves nothing.

Where to read

TopicResource
Query priority, getBy/queryBy/findBy, role and name, within, absence, screen, text matching, test IDsqueries.md
userEvent.setup(), forms, keyboard and focus, uploads, clipboard, pointer-events: none, fireEvent casesuser-events.md
findBy, waitFor rules, waitForElementToBeRemoved, act warnings, fake timers in Vitestasync.md
Packages, vitest.config.ts, cleanup without globals, jsdom vs browser mode, jsdom gaps, custom render, renderHook, StrictModesetup.md
What to mock, MSW 3 setup and error paths, vi.mock and vi.hoisted, next/navigation, spiesnetwork-and-mocks.md
Async Server Components, Server Functions, useActionState forms, what goes to E2Eserver-components.md

The traps that cost the most time

SymptomCauseRead
Every test after a fake-timer test hangs until timeoutvi.useFakeTimers() with defaults: Testing Library only detects Jest's fake timers, so findBy, waitFor, and await user.* wait on a frozen setTimeoutasync.md
Found multiple elements in the second test of a fileVitest globals is off by default, so RTL's auto cleanup never registeredsetup.md
An absence check can never failexpect(queryBy...).toBeDefined(): null is definedqueries.md
Assertion runs before the click finished, at randomMissing await on a user-event calluser-events.md
Click handler fires twice, or a request is sent repeatedlySide effect inside a waitFor callback, which retriesasync.md
TypeError: window.matchMedia is not a functionjsdom has no matchMedia, ResizeObserver, IntersectionObserver, scrollIntoView, or dialog.showModalsetup.md
Unhandled requests reach the real network after upgrading MSWMSW 3 renamed onUnhandledRequest to onUnhandledFrame and ignores the old namenetwork-and-mocks.md
vi.mock factory says a variable is not definedvi.mock is hoisted above the file's declarations; use vi.hoistednetwork-and-mocks.md
Async page stays on its Suspense fallback, no errorRTL cannot render async Server Components; await the function or use E2Eserver-components.md
An update to X inside a test was not wrapped in act(...)A promise or timer settled after the test stopped waitingasync.md

Review checklist

  • Queries use ByRole with name, or ByLabelText/ByText; ByTestId only where no role or text exists
  • No role or aria-* added only for the test
  • Absence uses queryBy with .not.toBeInTheDocument(); nothing asserts toBeDefined() on a query
  • userEvent.setup() per test, and every user-event call is awaited
  • Late content uses findBy; waitFor holds one assertion and no side effects; no setTimeout sleeps
  • Fake timers under Vitest use shouldAdvanceTime: true and are restored in afterEach
  • The setup file imports @testing-library/jest-dom/vitest and calls cleanup (or globals: true)
  • The network is mocked with MSW and onUnhandledFrame: 'error'; the failure path has its own test
  • No mock of the component, hook, or helper under test
  • Assertions check what the user sees or what leaves the component, not internal state
  • The test fails when the feature it covers is broken on purpose

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.