Instructions
Improve test quality for React / Next.js projects using Vitest + React Testing Library (unit/component) and Playwright (E2E).
When to Use
- Use to write/improve Vitest, Testing Library, and Playwright tests.
- Prefer
tdd-vitestfor red-green-refactor methodology. - Prefer
pr-review-workflowwhen reviewing test quality in a PR.
Mode A - generate tests
- Identify the target component or route and existing test patterns in the repo.
- Add or extend tests under
__tests__/or colocated*.test.tsxmatching project convention. - Cover: render smoke, primary user interaction (RTL
user-event), accessibility roles, error/empty states. - For E2E: one happy path per critical flow; use
data-testidonly when roles are insufficient. - Provide
pnpm test(andpnpm exec playwright testif E2E added) commands.
Mode B - audit coverage gaps
- Map components/routes without tests.
- List missing cases: loading, error boundary, keyboard, mobile viewport.
- Output
file:lineor file path groups - no writes unless user asks to fix.
Outcomes
- Tests that run with
pnpm testwithout flakiness (no arbitrarysetTimeout). - Clear list of what is covered vs missing.
Output Rules
State mode. List new/changed test files. Show one example assertion block per major behavior.
Scope and boundaries
- In scope: Vitest, RTL, Playwright for Next/React frontends.
- Out of scope: changing production logic solely to make tests pass without user approval, snapshot-only tests with no behavior checks, testing third-party SaaS APIs live.
Safety
- tools_allowed: repo-files - edit test files and test config only unless user expands scope.
- Do not commit secrets; mock
fetchand env vars in tests. - Match lockfile; prefer
pnpmwhenpnpm-lock.yamlexists.
Troubleshooting
window is not defined: ensure jsdom environment in Vitest config or mark file as client component tests only.- Next.js router mocks: use
next/navigationmocks consistent with App Router version in the repo. - Playwright flakiness: prefer
getByRoleandexpectauto-waiting; avoid fixed sleeps.
Related skills
tdd-vitest- red-green-refactor strategycode-assistant- small diffs under testgithub-actions-ci- CI test jobs
GitHub: https://github.com/bh611627/skillcodex/tree/main/skills/testing-agent/SKILL.md
npm: https://www.npmjs.com/package/@skillcodex/skills