agentleFS
gohypergiantgohypergiant/agent-skills/skills/accelint-react-testing/AGENTS.md

agent-skills / accelint-react-testing

AGENTS.md24 starsChanged 3 months agoApache-2.0View on GitHub

Note: This document is mainly for agents and LLMs to follow when writing or reviewing React component tests with Testing Library. Humans may also find it useful, but guidance here is optimized for automation and consistency by AI-assisted workflows. Comprehensive guide for React Testing Library best practices, designed for AI agents and LLMs. Each rule includes one-line summaries here, with links to detailed examples in the references/ folder. Load reference files only when you need detailed implementation guidance for a…

The file

We split this AGENTS.md into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use accessible query hierarchy: getByRole > getByLabelText > getByText > getByTestId.

    line 41
  2. Distinctive:

    Use @testing-library/user-event for realistic interaction sequences, not fireEvent.

    line 49
  3. Distinctive:

    Create test utils that wrap components with Context, Redux, Router providers.

    line 57
  4. Distinctive:

    Never test implementation details, use container queries, rely on excessive snapshots, use queryBy for presence, or put side effects in …

    line 65

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “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
AGENTS.md

React Testing Library

Note: This document is mainly for agents and LLMs to follow when writing or reviewing React component tests with Testing Library. Humans may also find it useful, but guidance here is optimized for automation and consistency by AI-assisted workflows.


Abstract

Comprehensive guide for React Testing Library best practices, designed for AI agents and LLMs. Each rule includes one-line summaries here, with links to detailed examples in the references/ folder. Load reference files only when you need detailed implementation guidance for a specific rule.

Token efficiency principle: This guide maximizes knowledge delta by providing only expert-level insights and non-obvious patterns. All rules assume understanding React Testing Library basics, React fundamentals, and standard testing patterns. Focus is on non-obvious decisions, accessibility-first testing, and avoiding common pitfalls.


How to Use This Guide

  1. Start here: Scan the rule summaries to identify relevant optimizations
  2. Load references as needed: Click through to detailed examples only when implementing
  3. Progressive loading: Each reference file is self-contained with ❌/✅ examples

This structure minimizes context usage while providing complete implementation guidance when needed.


Quick Reference

  • 1.1 Query Priority - Use accessible queries before test IDs (role > label > text > testId)
  • 1.2 Query Variants - getBy for sync, findBy for async, queryBy for absence
  • 1.3 User Events - Use userEvent over fireEvent for realistic interactions
  • 1.4 Async Testing - Handle promises with findBy, waitFor, act patterns
  • 1.5 Custom Render - Wrap components with providers in test utils
  • 1.6 Accessibility Queries - Query by role, ARIA attributes, semantic HTML
  • 1.7 Anti-patterns - Avoid implementation details, container queries, wrapper usage

1. Testing Patterns

1.1 Query Priority

Use accessible query hierarchy: getByRole > getByLabelText > getByText > getByTestId. View detailed examples

1.2 Query Variants

getBy* for immediate presence, findBy* for async appearance, queryBy* to assert absence. View detailed examples

1.3 User Events

Use @testing-library/user-event for realistic interaction sequences, not fireEvent. View detailed examples

1.4 Async Testing

Handle async with findBy queries and waitFor; avoid act warnings with proper awaiting. View detailed examples

1.5 Custom Render

Create test utils that wrap components with Context, Redux, Router providers. View detailed examples

1.6 Accessibility Queries

Query by semantic roles and labels; test ensures accessibility by design. View detailed examples

1.7 Anti-patterns

Never test implementation details, use container queries, rely on excessive snapshots, use queryBy for presence, or put side effects in waitFor. View detailed examples

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.