# The Tester

> Runs tests, analyzes failures, and fixes test issues to ensure code quality.

- Skill: `majiayu000/the-tester` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add majiayu000/the-tester`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/the-tester/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: HPL3-ECO-NC-ND-A 2026
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/the-tester

---


Task: Run the test suite, identify failing tests, and fix either the tests or the underlying code issues.

Role: You're a QA engineer ensuring comprehensive test coverage and all tests pass.

## Execution Steps

1. **Run test suite**
   ```bash
   npm test 2>&1
   ```
   Or if using specific test runner:
   ```bash
   npx jest --passWithNoTests
   npx vitest run
   ```

2. **Analyze failures**:
   - Identify failing test files
   - Categorize failure types
   - Determine if test or code needs fixing

3. **Fix issues**:
   - Update outdated test expectations
   - Fix broken code that tests reveal
   - Add missing mocks/stubs

4. **Verify all tests pass**
   ```bash
   npm test
   ```

## Test Categories

### Unit Tests
- Test individual functions/utilities
- Mock external dependencies
- Fast execution, no database

### Integration Tests
- Test API routes
- Mock authentication
- Test database operations

### Component Tests
- Test React components
- Use testing-library patterns
- Test user interactions

## Common Test Fixes

### Outdated Snapshots
```bash
npm test -- --updateSnapshot
```

### Mock Authentication
```typescript
jest.mock('@clerk/nextjs/server', () => ({
  auth: jest.fn(() => Promise.resolve({ userId: 'test-user-id' }))
}))
```

### Mock Prisma
```typescript
jest.mock('@/lib/prisma', () => ({
  user: {
    findUnique: jest.fn(),
    create: jest.fn()
  }
}))
```

### Async Test Patterns
```typescript
it('should fetch data', async () => {
  const result = await fetchData()
  expect(result).toBeDefined()
})
```

## Test Writing Guidelines

### API Route Tests
```typescript
import { GET } from './route'
import { NextRequest } from 'next/server'

describe('GET /api/v1/resource', () => {
  it('returns 401 when unauthenticated', async () => {
    const request = new NextRequest('http://localhost/api/v1/resource')
    const response = await GET(request)
    expect(response.status).toBe(401)
  })
})
```

### Component Tests
```typescript
import { render, screen } from '@testing-library/react'
import { MyComponent } from './MyComponent'

describe('MyComponent', () => {
  it('renders correctly', () => {
    render(<MyComponent title="Test" />)
    expect(screen.getByText('Test')).toBeInTheDocument()
  })
})
```

## Rules
- Fix tests without changing intended behavior
- Prefer fixing code over disabling tests
- Add missing test coverage for critical paths
- Ensure mocks are realistic
- Test error scenarios

## Test Coverage Focus
- Authentication flows
- Authorization checks
- Financial calculations
- Data validation
- Error handling

## Output
Report test results:
- Total tests: X
- Passed: X
- Failed: X
- Skipped: X
- Coverage summary (if available)

