Testing patterns for unit, integration, and E2E tests. Mock patterns for Supabase, Redis, OpenAI. Use when writing tests or setting up test infrastructure.
View on GitHubFebruary 1, 2026
Select agents to install to:
npx add-skill https://github.com/mnthe/hardworker-marketplace/blob/main/plugins/ultrawork/skills/testing-patterns/SKILL.md -a claude-code --skill testing-patternsInstallation paths:
.claude/skills/testing-patterns/# Testing Patterns
Comprehensive testing patterns including unit tests, integration tests, E2E tests, and mocking strategies for common services.
## When to Use
- Writing new features (TDD)
- Testing API endpoints
- Testing React components
- Mocking external services
- Setting up E2E tests
- Verifying user flows
## Test Types Overview
| Test Type | Scope | Speed | Examples |
|-----------|-------|-------|----------|
| Unit | Individual functions/components | Fast (< 50ms) | Pure functions, utilities, hooks |
| Integration | Multiple components/modules | Medium (< 1s) | API endpoints, database operations |
| E2E | Complete user flows | Slow (2-10s) | Login flow, checkout, search |
## Unit Testing Patterns
### Testing Pure Functions
```typescript
// src/lib/utils.ts
export function calculateProbability(yesVotes: number, noVotes: number): number {
const total = yesVotes + noVotes
if (total === 0) return 0.5
return yesVotes / total
}
// src/lib/utils.test.ts
import { calculateProbability } from './utils'
describe('calculateProbability', () => {
it('returns 0.5 for equal votes', () => {
expect(calculateProbability(10, 10)).toBe(0.5)
})
it('returns 0.5 for zero votes', () => {
expect(calculateProbability(0, 0)).toBe(0.5)
})
it('calculates correct probability for yes bias', () => {
expect(calculateProbability(75, 25)).toBe(0.75)
})
it('calculates correct probability for no bias', () => {
expect(calculateProbability(25, 75)).toBe(0.25)
})
it('handles edge case of one vote', () => {
expect(calculateProbability(1, 0)).toBe(1)
expect(calculateProbability(0, 1)).toBe(0)
})
})
```
### Testing React Components
```typescript
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MarketCard } from './MarketCard'
describe('MarketCard', () => {
const mockMarket = {
id: '1',
name: 'Test Market',
description: 'Test descriptio