| name | testing-patterns |
| description | Testing patterns for unit, integration, and end-to-end tests. Use when writing tests, setting up test fixtures, or validating RLS enforcement. Routes to existing test conventions.
|
Testing Patterns Skill
Purpose
Guide consistent and effective testing. Routes to existing test patterns and provides evidence templates.
When This Skill Applies
- Writing unit or integration tests
- Setting up test fixtures with RLS
- Running test suites
- Packaging test evidence
Critical Rules
FORBIDDEN
const user = await prisma.user.findUnique({ where: { user_id } });
let sharedUser: User;
beforeAll(() => { sharedUser = createUser(); });
CORRECT
const user = await withSystemContext(prisma, "test", async (client) => {
return client.user.findUnique({ where: { user_id } });
});
beforeEach(() => {
const testUser = createTestUser();
});
const userId = `user-${crypto.randomUUID()}`;
Test Commands
{{TEST_UNIT_COMMAND}}
{{TEST_INTEGRATION_COMMAND}}
{{TEST_E2E_COMMAND}}
{{CI_VALIDATE_COMMAND}}
Test Directory Structure
__tests__/
├── unit/ # Fast, isolated tests
├── integration/ # API and database tests
├── e2e/ # End-to-end tests
└── setup.ts # Global setup
Evidence Template
**Test Execution Evidence**
**Test Suite**: [unit/integration/e2e]
**Files Changed**: [list files]
**Test Results:**
- Total Tests: [X]
- Passed: [X]
- Failed: [0]
**Commands Run:**
```bash
{{TEST_UNIT_COMMAND}} --coverage
## Reference
- **Jest Config**: `jest.config.js`
- **RLS Context**: `lib/rls-context.ts`
- **Pattern Library**: `patterns_library/testing/`