/core-skills:rtl-query-patternsfrom core-skills
Authoritative reference for React Testing Library query semantics — how getByText, findByText, getByRole, and within resolve against real DOM structures. Answers "which query should I use?" and "why isn't this matcher finding my element?" without requiring a test run.
Ships in core-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Authoritative reference for React Testing Library query semantics. Eliminates multi-pass uncertainty about which query to use and why a matcher isn't finding an element — without needing a test run to verify.
Introduced after extended planning uncertainty about whether getByText("Degraded") would match a <p> containing <span>Status:</span> Degraded (it does not — see rules below).
No capabilities required. Pure reference — works from pasted JSX or component source.
Optional: fs.read to read component source and identify the exact DOM structure.
RTL's getByText(string) with exact: true (the default) matches elements whose full normalised textContent equals the string exactly.
textContent of an element is the concatenation of all descendant text nodes, with whitespace collapsed. A bare text node is never a query target — only the nearest wrapping element is tested.
| DOM structure | Query | Matches? | Reason |
|---|---|---|---|
<div>Foo</div> | getByText("Foo") | ✓ | textContent = "Foo" exactly |
<p><span>Label:</span> Foo</p> | getByText("Foo") | ✗ | textContent = "Label: Foo" |
<p><span>Label:</span> Foo</p> | getByText(/Foo/) | ✓ | regex — matches any element whose textContent contains "Foo" |
<p><span>Label:</span> Foo</p> | getByText("Label: Foo") | ✓ | exact match on full textContent |
<li>worker_unreachable</li> | getByText("worker_unreachable") | ✓ | <li> textContent is exactly that string |
<span>Degraded</span> | getByText("Degraded") | ✓ | <span> textContent = exactly "Degraded" |
<p><span>Status:</span> Degraded</p> | getByText("Degraded") | ✗ | <p> textContent = "Status: Degraded"; <span> = "Status:" |
<p><span>Status:</span> Degraded</p> | getByText(/Degraded/) | ✓ | regex matches <p> |
Exact text in a leaf element (<li>, <span>, <td>, <button>) → getByText("exact text"). Most stable — prefer this when you control the component.
Text is part of a mixed-content element (label + value in the same <p>) → use regex getByText(/value/) or the full string getByText("Label: value").
Scoping to a container (e.g. a table row) → within(container).getByText(...):
const row = screen.getByTestId("skill-row-code-review");
within(row).getByText("stable");
Async data (element appears after fetch/state update) → findByText(...) or waitFor(...):
expect(await screen.findByText("loop")).toBeInTheDocument();
// or
await waitFor(() => expect(screen.getByText("loop")).toBeInTheDocument(), {
timeout: 5000,
});
Assert absence → queryByText(...) returns null instead of throwing:
expect(screen.queryByText("No data")).not.toBeInTheDocument();
Interactive elements → prefer getByRole("button", { name: "Sync Now" }) — more resilient than getByText.
screen.debug() before the failing line to print the current DOM.within() to scope, or add a data-testid to the component.Input: "Does getByText('Degraded') match <p><span>Status:</span> Degraded</p>?"
Output:
No. The <p> has textContent "Status: Degraded". The <span> has "Status:". Neither equals "Degraded".
Fix options:
getByText(/Degraded/) — regex matches <p> whose textContent contains "Degraded"getByText("Status: Degraded") — exact match on the full <p> text<span data-testid="status-value">Degraded</span> to the component, use getByTestIdInput: "How do I assert the status cell inside a specific skill row?"
Output:
const row = screen.getByTestId("skill-row-code-review");
expect(within(row).getByText("stable")).toBeInTheDocument();
Without within, getByText("stable") might match the wrong row if multiple rows share the same value.
Input: "My getByText('loop') fails — the data loads after render."
Output:
expect(await screen.findByText("loop")).toBeInTheDocument();
findByText is getByText wrapped in waitFor and returns a Promise. Always use it (or waitFor) when the element appears after a fetch, setTimeout, or React state update.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
35 skills in this plugin
/autoresearchAutonomously optimise any skill by running it repeatedly, scoring outputs against
binary evals, mutating the prompt, and keeping improvements. Based on Karpathy's
autoresearch methodology.
Use when: "optimise this skill", "improve this skill", "run autoresearch on",
"make this skill better", "self-improve skill", "benchmark skill", "eval my skill",
"run evals on". Outputs: an improved SKILL.md copy, a results log, and a changelog
of every mutation tried.
/changelogWhen to useGenerate structured changelog entries from git history, grouping commits by conventional prefix and flagging breaking changes./npx claudepluginhub internet-dot/ai-config-os --plugin core-skills