NestJS + Jest Testing Excellence

Generate and refactor NestJS unit, integration, and E2E tests with Jest.

Updated Apr 5, 2023
One-click install
npx skills add https://github.com/edneyreis999/zord-project --skill nestjs-jest-testing-excellence
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: NestJS + Jest Testing Excellence
Source: https://github.com/edneyreis999/zord-project/tree/main/claude-skills/nestjs-test-excellence
Command: npx skills add https://github.com/edneyreis999/zord-project --skill nestjs-jest-testing-excellence

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @nestjs/testing, @swc/jest, @types/jest, @types/supertest, chance, jest, sequelize, supertest.

What problem does it solve?

This Skill solves the challenge of writing high-quality, maintainable tests in NestJS projects, ensuring adherence to Clean Architecture and DDD principles while achieving mandatory code coverage. It eliminates the guesswork and manual effort in applying complex testing patterns.

Core Features & Use Cases

  • Automated Test Generation & Refactoring: Creates new unit, integration, and E2E tests or refactors existing ones following best practices.
  • Advanced Testing Patterns: Implements patterns like Fake Builders, Spy on Repository Methods, and test.each for comprehensive scenario coverage.
  • Optimized Test Environment: Configures Jest with SWC for speed, custom matchers, and helpers for database lifecycle management.
  • Use Case: When you're building a new feature in NestJS, activate this Skill to automatically generate a full suite of tests for your domain entities, application use cases, and API endpoints, ensuring 80% coverage and architectural compliance from the start.

Quick Start

Use the "NestJS + Jest Testing Excellence" skill to generate unit tests for the ProductService module, ensuring 80% code coverage and using in-memory repositories.

Frequently Asked Questions about NestJS + Jest Testing Excellence

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I achieve 80% code coverage in NestJS with Jest?

Code coverage in NestJS projects is measured by Jest using instrumentation of domain, application, and infrastructure layers. Achieve 80% by writing unit tests for domain entities, integration tests for application use cases, and E2E tests for API endpoints, leveraging in-memory repositories and test fixtures to isolate each layer and maximize coverage density.

How do I structure unit tests for NestJS services using Clean Architecture?

Structure unit tests by separating domain logic (no NestJS imports), application use cases, and infrastructure concerns into distinct test suites. Use Fake Builders to generate test data, in-memory repositories to replace database dependencies, and Jest's test.each for scenario coverage across layers while maintaining architectural boundaries.

Can I use Jest with NestJS for both unit and integration testing?

Jest works with NestJS for unit, integration, and E2E testing. Configure Jest with SWC for performance, use @nestjs/testing for module setup, supertest for HTTP assertions, and implement per-layer testing strategies: mocked repositories for units, real database fixtures for integrations, and full API flows for E2E tests.

What's the best way to set up test fixtures and builders for NestJS projects?

Implement Fake Builders as factory objects that generate domain entities with realistic test data using libraries like chance. Store fixtures per layer, use in-memory repositories as test doubles, and configure Jest helpers for database lifecycle management to ensure tests are fast, deterministic, and reusable across unit, integration, and E2E suites.

How do I configure Jest for optimal performance in NestJS testing?

Configure Jest with @swc/jest for faster transpilation, @types/jest for type safety, and custom matchers for domain-specific assertions. Enable test parallelization, use in-memory repositories instead of real databases for unit tests, and organize test files by layer to minimize setup overhead and reduce overall test execution time.

Why should domain logic avoid NestJS imports in test design?

Removing NestJS imports from domain layer tests ensures business logic remains framework-agnostic and testable in isolation without framework dependencies. This design-for-test pattern improves test speed, makes logic portable across frameworks, and enforces Clean Architecture boundaries so domain tests focus purely on entity behavior and rules.