testing-react

testing-react is a cursor rule for coding agents from adonai-labs/agent-runway. It costs 0 tokens per session (2,462 once invoked), scanned A, original, MIT.

Testing guidance for React components with React Testing Library, including hooks, shared state, asynchronous behaviour, and accessibility.

In plain words
What is it for?
Use it to test rendered components, buttons and forms, hooks, context providers, asynchronous updates, and accessible user interactions.
Why use it?
It helps tests check what users see and do instead of depending on a component's internal implementation, making them less fragile.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/adonai-labs/agent-runway/testing-react
Clone the repo
git clone --depth 1 https://github.com/adonai-labs/agent-runway

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for testing-react

README.md
[![agentmods](https://agentmods.dev/badge/rules/adonai-labs/agent-runway/testing-react.svg)](https://agentmods.dev/rules/adonai-labs/agent-runway/testing-react)
Your own site
<a href="https://agentmods.dev/rules/adonai-labs/agent-runway/testing-react"><img src="https://agentmods.dev/badge/rules/adonai-labs/agent-runway/testing-react.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,462 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02462
Opus 5 $0.00000 $0.01231
Sonnet 5 $0.00000 $0.00492
Haiku 4.5 $0.00000 $0.00246

Measured yesterday against content hash 3334eb127581, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

testing-react scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

src/stacks/react/testing-react.mdc · 407 lines

How it starts

The opening of the file, as written. The whole thing — 407 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Testing React Applications

Extends core/rules/testing.mdc with React-specific testing patterns using React Testing Library.


Component Testing Principles

  • Test behavior, not implementation: Focus on what the user sees and does
  • Avoid testing internal state: Test outputs (rendered DOM, calls to callbacks)
  • Use accessible queries: Prefer getByRole, getByLabelText over getByTestId
  • Write tests that resemble how users interact: Click buttons, type in inputs, see text

React Testing Library Queries

Query Priority (from most to least preferred)

import { render, screen } from '@testing-library/react';

// 1. Accessible by everyone (best)
screen.getByRole('button', { name: /submit/i });
screen.getByLabelText('Email address');
screen.getByPlaceholderText('Enter email');
screen.getByText('Welcome');

// 2. Semantic queries
screen.getByAltText('Profile picture');
screen.getByTitle('Close dialog');

// 3. Test IDs (last resort)
screen.getByTestId('custom-element');

Query Variants

// getBy* - throws error if not found
const button = screen.getByRole('button');

// queryBy* - returns null if not found
const button = screen.queryByRole('button');
expect(button).not.toBeInTheDocument();

// findBy* - async, waits for element
const button = await screen.findByRole('button');

// getAllBy*, queryAllBy*, findAllBy* - for multiple elements
const items = screen.getAllByRole('listitem');

Testing Components

Basic Component Test

import { render, screen } from '@testing-library/react';
import { UserProfile } from './UserProfile';

describe('UserProfile', () => {
  it('should display user name and email', () => {
    render(<UserProfile name="John Doe" email="[email protected]" />);

    expect(screen.getByText('John Doe')).toBeInTheDocument();
    expect(screen.getByText('[email protected]')).toBeInTheDocument();
  });
});

Testing User Interactions

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { LoginForm } from './LoginForm';

describe('LoginForm', () => {
  it('should call onSubmit with email and password', async () => {
    const user = userEvent.setup();
    const handleSubmit = jest.fn();

    render(<LoginForm onSubmit={handleSubmit} />);

    await user.type(screen.getByLabelText('Email'), '[email protected]');
    await user.type(screen.getByLabelText('Password'), 'password123');
    await user.click(screen.getByRole('button', { name: /sign in/i }));

    expect(handleSubmit).toHaveBeenCalledWith({
      email: '[email protected]',
      password: 'password123',
    });
  });
});

Read the full file on GitHub · 407 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 407 lines · 0 tokens per session scan A 3334eb127581

Subscribe to this mod's changes

testing-react is a cursor rule published in the GitHub repository adonai-labs/agent-runway (2 stars, last pushed 15d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,462 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.