Use when writing acceptance criteria for a task - express each as an observable Given/When/Then that QA can execute, including negative cases
日本語の概要は準備中です。原文の説明を表示しています。
Use when writing or changing any React component - React Testing Library tests are behavior-focused (byRole first), use user-event, assert on accessible output, one behavior per test, and run in npm test
インストール方法を見るインストールする前に、エージェントに与えられる指示の中身を確認できます。
A component test that queries by data-testid or asserts on internal state proves the implementation didn't change, not that the component works for a user. React Testing Library tests must exercise the component the way a user (and a screen reader) does: find things by role/label/text, interact with them, and assert on what actually rendered.
Core principle: Test behavior, not implementation. If a refactor that keeps the same user-facing behavior breaks the test, the test is coupled to the wrong thing.
byRole first. Prefer getByRole (with { name: ... }) over byLabelText/byText, and both over byTestId. byTestId is a last resort for a node with no accessible role or text — reach for it only when nothing else identifies the element, and treat its presence as a smell worth a follow-up (usually a missing label/role, per accessibility-basics).user-event over fireEvent. fireEvent.click fires one DOM event; userEvent.click simulates the real sequence of events a browser produces (focus, pointer, keyboard) and catches bugs fireEvent cannot (e.g. a control that only works because it happens to be focused). Always await userEvent.setup() / await user.click(...).aria-* state (aria-expanded, aria-invalid, aria-disabled), and focus — not component internals, prop values, or CSS class names."shows a validation error when the field is left empty"), not "renders correctly". Multiple assertions are fine as long as they all check the same behavior; a second, unrelated behavior gets its own test.npm test. New component test files must run under the project's existing npm test script (Vitest/Jest) with no extra flags — a suite that only runs when invoked by hand is not part of the pipeline (see ci-cd-pipeline-authoring).// ❌ implementation-coupled: breaks on any internal refactor, proves nothing
// about what the user sees
test("renders correctly", () => {
render(<LoginForm />);
expect(screen.getByTestId("submit-btn")).toBeInTheDocument();
});
// ✅ behavior-focused: fails only when the real user-facing behavior breaks
test("shows a validation error when submitting with an empty email", async () => {
const user = userEvent.setup();
render(<LoginForm />);
await user.click(screen.getByRole("button", { name: /sign in/i }));
expect(screen.getByRole("alert")).toHaveTextContent(/email is required/i);
expect(screen.getByRole("textbox", { name: /email/i })).toHaveAttribute("aria-invalid", "true");
});
The second test finds the button and field the way a user would (by their accessible name), drives them with user-event, and asserts on what actually appears — it stays green through any internal rewrite that keeps this behavior.
data-testid when a role/label query would work — usually a sign the component is missing an accessible name in the first place.fireEvent for anything a real user would do with a mouse or keyboard.*.test.tsx file that npm test never picks up (wrong glob, wrong location) — decoration, not a gate.screen.getByTestId(...) with no comment on why no role/label query worked.fireEvent anywhere a user-event equivalent exists.npm test in CI never runs the new file.まだレビューはありません。使ってみた感想をお寄せください。
概要と使いどころ
Use when writing acceptance criteria for a task - express each as an observable Given/When/Then that QA can execute, including negative cases
日本語の概要は準備中です。原文の説明を表示しています。
Use when the diff adds or changes an endpoint, resolver, RPC, job or query that takes an object id, a role check, a request binding or a tenant filter - BOLA/IDOR, function-level authorization, mass assignment and tenant scoping
日本語の概要は準備中です。原文の説明を表示しています。
Use on every UI change - semantic HTML, labels for controls, keyboard-navigable dialogs/menus, visible focus, and never color as the only signal
日本語の概要は準備中です。原文の説明を表示しています。
Use when a task changes any screen, form, dialog, menu or control - Lighthouse/axe scan of the changed screens, a keyboard walk, and the thresholds that fail a task
日本語の概要は準備中です。原文の説明を表示しています。
How to work a task returned with review, QA or UAT findings. Use when a task is in need_revision or PR review comments are in your context.
日本語の概要は準備中です。原文の説明を表示しています。
Use when deciding whether a request needs an analiz task before implementation - the conditions that require the architect's analysis versus going straight to implementation
日本語の概要は準備中です。原文の説明を表示しています。