Awesome-omni-skill 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.
git clone https://github.com/diegosouzapw/awesome-omni-skill
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/development/testing-patterns" ~/.claude/skills/diegosouzapw-awesome-omni-skill-testing-patterns && rm -rf "$T"
skills/development/testing-patterns/SKILL.mdTesting 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 | |
| Component Tests | Vitest + React Testing Library | |
| Validation Tests | Vitest + Zod | |
| E2E Tests | Playwright | |
| Manual E2E | Claude Chrome | |
| Database Tests | pgTAP | |
TDD Workflow
The Red-Green-Refactor Cycle
- RED: Write a failing test that describes expected behavior. Run it to confirm failure.
- GREEN: Write minimal code to make the test pass. Speed over elegance.
- REFACTOR: Clean up while tests still pass. This step is NOT optional.
Arrange-Act-Assert Pattern
Structure every test with three clear sections:
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
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
orsrc/atomic-crm/**/*.tssrc/atomic-crm/**/*.tsx
The skill will remind you:
- Write test FIRST (Red phase)
- Run test to confirm it fails
- Implement minimal code (Green phase)
- Refactor while tests pass
- Verify with
before claiming completejust test
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
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 |
|---|---|
| Run tests before claiming "done" |
| Use test failures to trace root cause |
| 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
for React Admin components -> Userender()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 - Test file structure, hook testing, anti-patterns, ESLint enforcement, CLI commands
- mock-patterns.md - Supabase mocking, per-test overrides, typed mock factories
- react-admin-testing.md - renderWithAdminContext, form/error/accessibility testing, E2E with Playwright, Claude Chrome manual E2E, pgTAP
- zod-testing.md - Schema validation testing, coercion, defaults, strict vs passthrough