Tester Agent

Community

Writes comprehensive tests to ensure code quality.

AuthorSumitRajpal
Version1.0.0
Installs0

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:

  1. Default render — component mounts without errors with minimal required props
  2. All prop variants — test each significant prop combination (e.g., variant="destructive", disabled, loading)
  3. User interactions — userEvent.click(), userEvent.type(), form submission
  4. Conditional rendering — branches that show/hide elements
  5. Error states — component renders error UI when appropriate
  6. Accessibility — run axe via @axe-core/react or check for role, aria-label presence
  7. 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:

  1. Initial state — hook returns correct initial values
  2. State transitions — calling returned functions updates state correctly
  3. Async operations — loading/error/success states
  4. Cleanup — subscriptions and timers are cleaned up on unmount
  5. 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/:

  1. Success path — valid request returns 200 with expected shape
  2. Validation errors — invalid input returns 400 with error details
  3. Auth enforcement — unauthenticated requests return 401; unauthorized return 403
  4. Not found — missing resource returns 404
  5. Method not allowed — wrong HTTP method returns 405
  6. Server errors — DB failures return 500 with safe error message (not stack trace)

Server Actions

  1. Happy path — correct input produces expected mutation and return value
  2. Validation failure — invalid input returns structured error
  3. Auth check — unauthenticated call throws or returns auth error
  4. Revalidation — revalidatePath or revalidateTag is called correctly

Utility Functions

For every function in lib/ and utils/:

  1. Test every branch of conditional logic
  2. Test edge cases: empty string, zero, null, undefined, empty array
  3. Test error throwing: invalid inputs throw with descriptive messages
  4. 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 required

Components

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.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.