Skip to content
jest-nestjs logo

Jest Nestjs

jest-nestjs

Jest + NestJS testing patterns for unit and e2e tests in Aurora projects. Trigger: When writing tests, mocking dependencies, or implementing test coverage in NestJS/Aurora.

SKILL.md

Full skill instructions

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

Best Practices

✅ DO

  1. Isolate tests: Each test should be independent
  2. Use descriptive names: "should throw error when price is negative"
  3. Follow AAA pattern: Arrange, Act, Assert
  4. Mock external dependencies: Database, APIs, services
  5. Test edge cases: Null, undefined, empty arrays, boundaries
  6. Test error paths: Exceptions, validation errors
  7. Use factories/​fixtures: Reusable test data builders
  8. Keep tests fast: Unit tests < 100ms, e2e < 1s
  9. Clean up: Use afterEach to reset state
  10. Test one thing: One assertion per test (when possible)

❌ DON'T

  1. Don't test implementation details: Test behavior, not internals
  2. Don't test framework code: Trust NestJS, TypeORM, etc.
  3. Don't share state: Between tests or describe blocks
  4. Don't use real database: In unit tests (use mocks)
  5. Don't skip tests: Fix or remove broken tests
  6. Don't test getters/​setters: Unless they have logic
  7. Don't duplicate tests: Avoid redundant test cases
  8. Don't test generated code: Trust Aurora generation (test custom logic only)
  9. 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

TaskPattern
Test handlerTest.createTestingModule() + mock repository
Mock repositoryUse custom mock class implementing interface
Test validationExpect exception to be thrown
e2e RESTsupertest + app.getHttpServer()
e2e GraphQLsupertest + GraphQL query string
Test aggregateCall methods + verify events
Test VOConstructor + validation rules
Coveragenpm run test:cov

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 #region AI-generated code in handlers
  • TDD when possible: Write test → Implement → Refactor

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View