testing-patterns

TDD and unit testing guidance for Crispy CRM. Use when writing tests, implementing TDD, debugging test failures, or setting up test infrastructure. Covers Vitest patterns, React Admin component testing, Zod schema validation testing, Supabase mocking, E2E with Playwright, and manual E2E testing with Claude Chrome. Integrates with verification-before-completion for test verification.

16 stars

Best use case

testing-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

TDD and unit testing guidance for Crispy CRM. Use when writing tests, implementing TDD, debugging test failures, or setting up test infrastructure. Covers Vitest patterns, React Admin component testing, Zod schema validation testing, Supabase mocking, E2E with Playwright, and manual E2E testing with Claude Chrome. Integrates with verification-before-completion for test verification.

Teams using testing-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/testing-patterns/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/development/testing-patterns/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/testing-patterns/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How testing-patterns Compares

Feature / Agenttesting-patternsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

TDD and unit testing guidance for Crispy CRM. Use when writing tests, implementing TDD, debugging test failures, or setting up test infrastructure. Covers Vitest patterns, React Admin component testing, Zod schema validation testing, Supabase mocking, E2E with Playwright, and manual E2E testing with Claude Chrome. Integrates with verification-before-completion for test verification.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Testing Patterns for Crispy CRM

## Overview

Comprehensive testing guidance for the Crispy CRM codebase. Covers unit testing with Vitest, component testing with React Admin context, validation testing with Zod schemas, and E2E testing with Playwright.

**Philosophy:** Tests should verify behavior, not implementation. Focus on what the code does, not how it does it.

## When to Use

Use this skill when:
- Writing new tests (unit, integration, E2E)
- Implementing TDD (Test-Driven Development)
- Debugging failing tests
- Setting up test infrastructure
- Mocking Supabase or React Admin
- Understanding test coverage requirements
- Writing Claude Chrome manual E2E prompts

## Test Stack

| Layer | Tool | Location |
|-------|------|----------|
| **Unit Tests** | Vitest | `src/**/__tests__/*.test.ts` |
| **Component Tests** | Vitest + React Testing Library | `src/**/__tests__/*.test.tsx` |
| **Validation Tests** | Vitest + Zod | `src/atomic-crm/validation/__tests__/` |
| **E2E Tests** | Playwright | `tests/e2e/` |
| **Manual E2E** | Claude Chrome | `docs/tests/e2e/` |
| **Database Tests** | pgTAP | `supabase/tests/` |

## TDD Workflow

### The Red-Green-Refactor Cycle

1. **RED:** Write a failing test that describes expected behavior. Run it to confirm failure.
2. **GREEN:** Write minimal code to make the test pass. Speed over elegance.
3. **REFACTOR:** Clean up while tests still pass. This step is NOT optional.

### Arrange-Act-Assert Pattern

Structure every test with three clear sections:

```typescript
it('calculates total with tax', () => {
  // Arrange: Set up test data
  const items = [{ price: 100 }, { price: 50 }];
  const taxRate = 0.1;

  // Act: Execute the code
  const total = calculateTotalWithTax(items, taxRate);

  // Assert: Verify the outcome
  expect(total).toBe(165);
});
```

### Where TDD Thrives

| Domain | TDD Effectiveness | Why |
|--------|-------------------|-----|
| **Validation schemas** | Excellent | Well-defined inputs/outputs |
| **Pure functions** | Excellent | No side effects |
| **Data providers** | Very Good | Clear API contracts |
| **Hooks** | Very Good | Isolated logic |
| **Components** | Good | Need user interaction testing |
| **UI layout** | Fair | Visual verification better |

### TDD in Watch Mode

```bash
just test:watch
# 1. Write failing test -> See RED in terminal
# 2. Write code -> See GREEN
# 3. Refactor -> Confirm still GREEN
# 4. Commit -> Repeat
```

### Common TDD Pitfalls

| Pitfall | Problem | Fix |
|---------|---------|-----|
| Skipping refactor | Technical debt accumulates | Refactor after EVERY green |
| Testing implementation | Brittle tests break on refactor | Test inputs -> outputs only |
| Writing tests after code | Confirmation bias | Discipline: test FIRST |
| Chasing 100% coverage | Meaningless tests | Focus on behavior coverage |
| Giant test steps | Hard to debug failures | Small increments |

## Automatic Activation

This skill activates automatically for implementation tasks. When you see:
- "implement feature", "create component", "add handler", "new schema"
- Any file modification in `src/atomic-crm/**/*.ts` or `src/atomic-crm/**/*.tsx`

**The skill will remind you:**
1. Write test FIRST (Red phase)
2. Run test to confirm it fails
3. Implement minimal code (Green phase)
4. Refactor while tests pass
5. Verify with `just test` before claiming complete

### Integration with verification-before-completion

Testing is now enforced at completion time:
- Cannot claim "done" without test evidence
- Cannot claim "feature complete" without passing tests
- UI changes prompt for Manual E2E via Claude Chrome

## Quick Reference

### Running Tests

```bash
just test              # All unit tests
just test:watch        # Watch mode for TDD
just test:coverage     # Generate coverage report
just test:ui           # Vitest UI for debugging
npx playwright test    # E2E tests
npx supabase test db   # Database tests
```

### Coverage Requirements

| Type | Minimum | Target |
|------|---------|--------|
| **Validation schemas** | 90% | 100% |
| **Data providers** | 80% | 90% |
| **Components** | 70% | 80% |
| **Hooks** | 80% | 90% |
| **E2E critical paths** | 100% | 100% |

## Integration with Other Skills

| Skill | Integration |
|-------|-------------|
| `verification-before-completion` | Run tests before claiming "done" |
| `fail-fast-debugging` | Use test failures to trace root cause |
| `enforcing-principles` | Tests verify schema validation at API boundary |

## Decision Tree

```
Need to write tests?
|
+- New feature?
|  +- Start with TDD -> Write failing test first
|
+- Bug fix?
|  +- Write test that reproduces bug -> Fix -> Verify passes
|
+- Validation logic?
|  +- Test Zod schemas -> Valid/invalid inputs, coercion, defaults
|
+- React component?
|  +- Use renderWithAdminContext -> Test user interactions
|
+- Database logic?
|  +- pgTAP tests -> RLS policies, constraints, triggers
|
+- Full user journey?
   +- Playwright E2E -> Critical path scenarios
```

## Red Flags - STOP and Review

If you find yourself:
- Writing tests after code is "done" -> Consider TDD next time
- Testing internal state -> Test behavior instead
- Skipping async waitFor -> Race condition risk
- Using raw `render()` for React Admin components -> Use `renderWithAdminContext`
- No assertions in test -> Test is meaningless
- Massive snapshots -> Use specific assertions

**Remember:** Tests are documentation. They should clearly express what the code does.

## Resources

For detailed implementation patterns, see the reference files below:

- [vitest-patterns.md](references/vitest-patterns.md) - Test file structure, hook testing, anti-patterns, ESLint enforcement, CLI commands
- [mock-patterns.md](references/mock-patterns.md) - Supabase mocking, per-test overrides, typed mock factories
- [react-admin-testing.md](references/react-admin-testing.md) - renderWithAdminContext, form/error/accessibility testing, E2E with Playwright, Claude Chrome manual E2E, pgTAP
- [zod-testing.md](references/zod-testing.md) - Schema validation testing, coercion, defaults, strict vs passthrough

<!-- @resource references/vitest-patterns.md "Vitest configuration and test patterns" -->
<!-- @resource references/mock-patterns.md "Mock setup and typed factories" -->
<!-- @resource references/react-admin-testing.md "React Admin component testing, E2E, and database testing" -->
<!-- @resource references/zod-testing.md "Zod schema validation testing patterns" -->

Related Skills

ui-patterns

16
from diegosouzapw/awesome-omni-skill

Plaited UI patterns for templates, behavioral elements, and styling. Use when creating bElements or FunctionalTemplates, writing stories for testing, using createStyles, building form controls, or coordinating cross-island communication.

typescript-testing

16
from diegosouzapw/awesome-omni-skill

Comprehensive testing guidance for TypeScript projects including unit testing patterns, mocking strategies, and test organization best practices

testing-tauri-apps

16
from diegosouzapw/awesome-omni-skill

Guides developers through testing Tauri applications including unit testing with mock runtime, mocking Tauri APIs, WebDriver end-to-end testing with Selenium and WebdriverIO, and CI integration with GitHub Actions.

testing-strategy-python

16
from diegosouzapw/awesome-omni-skill

Python/FastAPI/Django testing conventions. pytest, fixtures, httpx, TestClient, factory_boy. Use when writing or reviewing Python tests.

testing-strategy-builder

16
from diegosouzapw/awesome-omni-skill

Use this skill when creating comprehensive testing strategies for applications. Provides test planning templates, coverage targets, test case structures, and guidance for unit, integration, E2E, and performance testing. Ensures robust quality assurance across the development lifecycle.

testing-skills-activation

16
from diegosouzapw/awesome-omni-skill

Use when creating or refining Claude Code skills to validate that skill descriptions trigger correctly - provides systematic testing methodology for skill activation patterns using test cases and automated evaluation

Testing Skill

16
from diegosouzapw/awesome-omni-skill

Automatiza pruebas y diagnósticos del sistema SmartK et sin perder tiempo

testing-qa

16
from diegosouzapw/awesome-omni-skill

Comprehensive testing and QA workflow covering unit testing, integration testing, E2E testing, browser automation, and quality assurance.

testing-principles

16
from diegosouzapw/awesome-omni-skill

Language-agnostic testing principles including TDD, test quality, coverage standards, and test design patterns. Use when writing tests, designing test strategies, or reviewing test quality.

testing-builder

16
from diegosouzapw/awesome-omni-skill

Automatically generates comprehensive test suites (unit, integration, E2E) based on code and past testing patterns. Use when user says "write tests", "test this", "add coverage", or after fixing bugs to create regression tests. Eliminates testing friction for ADHD users.

Testing Anti-Patterns

16
from diegosouzapw/awesome-omni-skill

This skill should be used when encountering "flaky tests", "test maintenance issues", "slow test suites", "brittle tests", "test code smells", "test debugging problems", or when tests are hard to understand, maintain, or debug.

tailwind-patterns

16
from diegosouzapw/awesome-omni-skill

Tailwind CSS v4 principles. CSS-first configuration, container queries, modern patterns, design token architecture.