Tester Agent
CommunityWrites comprehensive tests to ensure code quality.
System Documentation
What problem does it solve?
Automates the creation of thorough tests for Next.js 14+ projects, ensuring code quality and full coverage.
Core Features & Use Cases
- Unit/Integration: Vitest + React Testing Library
- E2E: Playwright
- Mocking: vi.mock(), msw (Mock Service Worker) for API mocking
- Database: Test with a real Postgres test DB or in-memory SQLite via Prisma
- Coverage: Istanbul (built into Vitest)
What to Test
React Components
For every React component, generate tests covering:
- Default render — component mounts without errors with minimal required props
- All prop variants — test each significant prop combination (e.g., variant="destructive", disabled, loading)
- User interactions — userEvent.click(), userEvent.type(), form submission
- Conditional rendering — branches that show/hide elements
- Error states — component renders error UI when appropriate
- Accessibility — run axe via @axe-core/react or check for role, aria-label presence
- Snapshot — only for highly stable presentational components; prefer explicit assertions
Example structure: describe('Button', () => { it('renders with default props', () => { ... }) it('renders loading spinner when isLoading=true', () => { ... }) it('calls onClick handler when clicked', async () => { ... }) it('is disabled when disabled=true', () => { ... }) it('applies destructive variant styles', () => { ... }) it('meets accessibility requirements', async () => { ... }) })
Custom Hooks
For every custom hook, generate tests covering:
- Initial state — hook returns correct initial values
- State transitions — calling returned functions updates state correctly
- Async operations — loading/error/success states
- Cleanup — subscriptions and timers are cleaned up on unmount
- Dependencies — hook re-runs when deps change
Use renderHook from React Testing Library.
API Routes (Route Handlers)
For every route.ts in src/app/api/:
- Success path — valid request returns 200 with expected shape
- Validation errors — invalid input returns 400 with error details
- Auth enforcement — unauthenticated requests return 401; unauthorized return 403
- Not found — missing resource returns 404
- Method not allowed — wrong HTTP method returns 405
- Server errors — DB failures return 500 with safe error message (not stack trace)
Server Actions
- Happy path — correct input produces expected mutation and return value
- Validation failure — invalid input returns structured error
- Auth check — unauthenticated call throws or returns auth error
- Revalidation — revalidatePath or revalidateTag is called correctly
Utility Functions
For every function in lib/ and utils/:
- Test every branch of conditional logic
- Test edge cases: empty string, zero, null, undefined, empty array
- Test error throwing: invalid inputs throw with descriptive messages
- For pure functions: use property-based testing when applicable
Quick Start
Generate comprehensive Vitest and Playwright tests for a given Next.js 14+ module, ensuring 100% test coverage for new code where applicable.
Dependency Matrix
Required Modules
None requiredComponents
Standard package💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: Tester Agent Download link: https://github.com/SumitRajpal/nextjs-claude-architecture/archive/main.zip#tester-agent Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.