test-component

test-component is a skill for Claude Code, Codex from MuhammadUsmanGM/claude-code-best-practices. It costs 50 tokens per session (501 once invoked), scanned A, original, MIT.

A workflow for writing tests for an existing React component with React Testing Library, a tool for checking user-visible behaviour in React interfaces. It follows the project's existing test style and prefers queries based on accessible roles and labels.

In plain words
What is it for?
Use it to add tests beside a React component, covering its initial display, user interactions, states, and callbacks. Network requests are tested through the project's shared request boundary rather than by mocking component internals.
Why use it?
It keeps tests focused on what users can see and do instead of the component's internal implementation. It also encourages testing loading, empty, error, interaction, and callback behaviour where those cases exist.

Skill for Claude CodeCodex

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 skills/muhammadusmangm/claude-code-best-practices/test-component
Any agent
npx skills add MuhammadUsmanGM/claude-code-best-practices --skill test-component
Clone the repo
git clone --depth 1 https://github.com/MuhammadUsmanGM/claude-code-best-practices

Made for: Claude Code, Codex.

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 test-component

README.md
[![agentmods](https://agentmods.dev/badge/skills/muhammadusmangm/claude-code-best-practices/test-component.svg)](https://agentmods.dev/skills/muhammadusmangm/claude-code-best-practices/test-component)
Your own site
<a href="https://agentmods.dev/skills/muhammadusmangm/claude-code-best-practices/test-component"><img src="https://agentmods.dev/badge/skills/muhammadusmangm/claude-code-best-practices/test-component.svg" alt="Measured on agentmods" height="20"></a>
Per session 50 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 501 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.00050 $0.00501
Opus 5 $0.00025 $0.00251
Sonnet 5 $0.00010 $0.00100
Haiku 4.5 $0.00005 $0.00050

Measured 5d ago against content hash 092129a518ce, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

test-component 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 5d ago.

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.

starters/react/.claude/skills/test-component/SKILL.md · 50 lines

What it actually says

Test Component

Write tests for an existing component following the project's conventions.

Steps

  1. Read the component file. Note its props, any hooks it calls, and whether it fetches data.
  2. Read one existing test file in the same area and mirror its style — imports, render helpers, matcher choices, mock setup.
  3. Plan 3–5 assertions, in this priority order:
    • Renders the expected role/label on mount.
    • Responds to user interaction (click, type) with a visible result.
    • Handles loading / empty / error states if the component has them.
    • Calls the right callback with the right args (if props include callbacks).
  4. Mock at the network boundary. If the component fetches via a shared client in src/api/, add an MSW handler in src/test/msw/ — don't mock the component's internal hooks.
  5. Write the test file next to the component. Name: <Name>.test.tsx.
  6. Run npm test -- <Name> once and report pass/fail. Do not fix the component to make the test pass — if a test reveals a bug, stop and tell the user.

Query priority (enforced)

Use in this order, only falling back when the higher option genuinely doesn't apply:

  1. getByRole with an accessible name
  2. getByLabelText
  3. getByPlaceholderText
  4. getByText
  5. getByTestId — last resort

Rules

  • Never call act() manually. If a test "needs" it, you're testing implementation — rewrite the assertion.
  • Never await new Promise(...) to wait for state. Use findBy* or waitFor.
  • No snapshot tests unless the component has a stable, small render surface (icons, formatted strings). Component snapshots rot fast.
  • Don't edit the component under test. This skill writes tests only.
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. 5d ago First seen · 50 lines · 50 tokens per session scan A 092129a518ce

Subscribe to this mod's changes

test-component is a skill published in the GitHub repository MuhammadUsmanGM/claude-code-best-practices (76 stars, last pushed 2mo ago), licensed MIT. It adds 50 tokens to every session and 501 once invoked, about $0.0003 per session on Opus 5. 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-08-30.

Related

Other skills, from other repositories