Testing Expert Skill
When to Use
- Writing unit tests
- Creating integration tests
- Setting up E2E tests
- Testing React components
- Testing API endpoints
- Testing database operations
- Setting up test infrastructure
- Reviewing test coverage
Project Context Discovery
- Scan Documentation: Check
.agents/memory/ for durable project context (architecture, deployment, gotchas)
- Identify Tools: Jest/Vitest, React Testing Library, Supertest, Playwright/Cypress
- Discover Patterns: Review existing test files, utilities, mocking patterns
- Use Project-Specific Skills: Check for
[project]-testing-expert skill
Core Testing Principles
Testing Pyramid
- Unit Tests (70%): Fast, isolated, test individual functions/components
- Integration Tests (20%): Test component interactions
- E2E Tests (10%): Test full user flows
Coverage Targets
- Line coverage: > 80%
- Branch coverage: > 75%
- Function coverage: > 85%
- Critical paths: 100%
Test Organization
src/
users/
users.controller.ts
users.controller.spec.ts # Unit tests
users.service.ts
users.service.spec.ts
__tests__/
integration/
e2e/
Test Quality (AAA Pattern)
it('should return users filtered by organization', async () => {
// Arrange: Set up test data
const organizationId = 'org1';
const expectedUsers = [{ organization: organizationId }];
// Act: Execute the code being tested
const result = await service.findAll(organizationId);
// Assert: Verify the result
expect(result).toEqual(expectedUsers);
});
Good Tests Are
- Independent (no test dependencies)
- Fast (< 100ms each)
- Repeatable (same result every time)
- Meaningful (test real behavior)
- Maintainable (easy to update)
Testing Best Practices Summary
- Test Isolation: Each test independent, clean up after
- Meaningful Tests: Test behavior, not implementation
- Mocking Strategy: Mock external dependencies, not what you're testing
- Test Data: Use factories, keep data minimal, clean up
- Coverage: High coverage, focus on critical paths
Integration
| Test Type |
Tools |
Use Case |
| Unit |
Jest/Vitest |
Functions, components, services |
| Integration |
Supertest + Jest |
Controller + Service + DB |
| E2E |
Playwright/Cypress |
Full user flows |
| Component |
React Testing Library |
React component behavior |
For complete React Testing Library examples, hook testing, Next.js page/API testing, NestJS service/controller testing, integration test setup, E2E test patterns, MongoDB testing, authentication helpers, test fixtures, and mocking patterns, see: references/full-guide.md
1---2name: testing-expert-43description: Expert in testing strategies for React, Next.js, and NestJS applications covering unit tests, integration tests, E2E tests, and testing best practices. Use when writing unit, integration, or E2E tests, testing React components, or testing API endpoints.4---56# Testing Expert Skill78## When to Use910- Writing unit tests11- Creating integration tests12- Setting up E2E tests13- Testing React components14- Testing API endpoints15- Testing database operations16- Setting up test infrastructure17- Reviewing test coverage1819## Project Context Discovery20211. **Scan Documentation:** Check `.agents/memory/` for durable project context (architecture, deployment, gotchas)222. **Identify Tools:** Jest/Vitest, React Testing Library, Supertest, Playwright/Cypress233. **Discover Patterns:** Review existing test files, utilities, mocking patterns244. **Use Project-Specific Skills:** Check for `[project]-testing-expert` skill2526## Core Testing Principles2728### Testing Pyramid2930- **Unit Tests** (70%): Fast, isolated, test individual functions/components31- **Integration Tests** (20%): Test component interactions32- **E2E Tests** (10%): Test full user flows3334### Coverage Targets3536- Line coverage: > 80%37- Branch coverage: > 75%38- Function coverage: > 85%39- Critical paths: 100%4041### Test Organization4243```44src/45 users/46 users.controller.ts47 users.controller.spec.ts # Unit tests48 users.service.ts49 users.service.spec.ts50 __tests__/51 integration/52 e2e/53```5455### Test Quality (AAA Pattern)5657```typescript58it('should return users filtered by organization', async () => {59 // Arrange: Set up test data60 const organizationId = 'org1';61 const expectedUsers = [{ organization: organizationId }];6263 // Act: Execute the code being tested64 const result = await service.findAll(organizationId);6566 // Assert: Verify the result67 expect(result).toEqual(expectedUsers);68});69```7071## Good Tests Are7273- Independent (no test dependencies)74- Fast (< 100ms each)75- Repeatable (same result every time)76- Meaningful (test real behavior)77- Maintainable (easy to update)7879## Testing Best Practices Summary80811. **Test Isolation:** Each test independent, clean up after822. **Meaningful Tests:** Test behavior, not implementation833. **Mocking Strategy:** Mock external dependencies, not what you're testing844. **Test Data:** Use factories, keep data minimal, clean up855. **Coverage:** High coverage, focus on critical paths8687## Integration8889| Test Type | Tools | Use Case |90|-----------|-------|----------|91| Unit | Jest/Vitest | Functions, components, services |92| Integration | Supertest + Jest | Controller + Service + DB |93| E2E | Playwright/Cypress | Full user flows |94| Component | React Testing Library | React component behavior |9596---9798**For complete React Testing Library examples, hook testing, Next.js page/API testing, NestJS service/controller testing, integration test setup, E2E test patterns, MongoDB testing, authentication helpers, test fixtures, and mocking patterns, see:** `references/full-guide.md`