Claude-skill-registry jest-nestjs
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/jest-nestjs" ~/.claude/skills/majiayu000-claude-skill-registry-jest-nestjs && rm -rf "$T"
manifest:
skills/data/jest-nestjs/SKILL.mdsource content
When to Use
Use this skill when:
- Writing unit tests for handlers, services, or aggregates
- Creating e2e tests for API endpoints
- Mocking NestJS dependencies (repositories, services, event bus)
- Testing CQRS commands and queries
- Testing Aurora-generated code
- Setting up test fixtures and factories
Testing Philosophy in Aurora/NestJS
Unit Tests: Test individual components in isolation
- Handlers (Command/Query), Services, Aggregates/Value Objects, Mappers
e2e Tests: Test complete flows through the API layer
- REST endpoints, GraphQL resolvers, Authentication, Database interactions
Detailed References
- Unit Testing Patterns — Command/query handlers, mocking repos, mocking external services, bus mocks
- E2E Testing Patterns — REST controllers, GraphQL resolvers
- Aurora-Specific Testing — Value objects, aggregates, test organization
Best Practices
✅ DO
- Isolate tests: Each test should be independent
- Use descriptive names: "should throw error when price is negative"
- Follow AAA pattern: Arrange, Act, Assert
- Mock external dependencies: Database, APIs, services
- Test edge cases: Null, undefined, empty arrays, boundaries
- Test error paths: Exceptions, validation errors
- Use factories/fixtures: Reusable test data builders
- Keep tests fast: Unit tests < 100ms, e2e < 1s
- Clean up: Use
to reset stateafterEach - Test one thing: One assertion per test (when possible)
❌ DON'T
- Don't test implementation details: Test behavior, not internals
- Don't test framework code: Trust NestJS, TypeORM, etc.
- Don't share state: Between tests or describe blocks
- Don't use real database: In unit tests (use mocks)
- Don't skip tests: Fix or remove broken tests
- Don't test getters/setters: Unless they have logic
- Don't duplicate tests: Avoid redundant test cases
- Don't test generated code: Trust Aurora generation (test custom logic only)
- Don't ignore coverage: Aim for >80% on custom code
Coverage Guidelines
Target Coverage:
- Custom handlers: 100% (all custom logic)
- Services: 90%+ (critical business logic)
- Aggregates: 90%+ (domain rules)
- Value Objects: 80%+ (validation logic)
- Controllers/Resolvers: 80%+ (e2e coverage acceptable)
- Generated code: Skip (trust Aurora)
Run Coverage:
npm run test:cov # Unit tests with coverage npm run test:e2e # e2e tests npm run test:watch # Watch mode for TDD
Jest Configuration
jest.config.js (typical Aurora setup):
module.exports = { moduleFileExtensions: ['js', 'json', 'ts'], rootDir: 'src', testRegex: '.*\\.spec\\.ts$', transform: { '^.+\\.(t|j)s$': 'ts-jest', }, collectCoverageFrom: [ '**/*.(t|j)s', '!**/*.module.ts', '!**/*.index.ts', '!**/node_modules/**', '!**/dist/**', '!**/infrastructure/seeds/**', ], coverageDirectory: '../coverage', testEnvironment: 'node', moduleNameMapper: { '^@app/(.*)$': '<rootDir>/$1', '^@core/(.*)$': '<rootDir>/@core/$1', '^@api/(.*)$': '<rootDir>/@api/$1', }, };
Quick Reference
| Task | Pattern |
|---|---|
| Test handler | + mock repository |
| Mock repository | Use custom mock class implementing interface |
| Test validation | Expect exception to be thrown |
| e2e REST | + |
| e2e GraphQL | + GraphQL query string |
| Test aggregate | Call methods + verify events |
| Test VO | Constructor + validation rules |
| Coverage | |
Remember
- Unit tests = Fast, isolated, mock dependencies
- e2e tests = Slow, integrated, real dependencies
- Test custom logic only: Don't test Aurora-generated code
- Mark your code: Use
in handlers#region AI-generated code - TDD when possible: Write test → Implement → Refactor