testing-guide-nestjs-project

Provides a structured NestJS 11 testing strategy for DI wiring, module compilation, and HTTP contracts.

Updated Apr 22, 2026
One-click install
npx skills add https://github.com/vanderleik/greenfiend-project --skill testing-guide-nestjs-project-vanderleik
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-guide-nestjs-project
Source: https://github.com/vanderleik/greenfiend-project/tree/main/.github/skills/testing-guide-nestjs-project
Command: npx skills add https://github.com/vanderleik/greenfiend-project --skill testing-guide-nestjs-project-vanderleik

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This comprehensive guide provides a structured approach to testing NestJS projects, ensuring DI wiring, module compilation, and HTTP contracts are validated across unit, integration, and E2E layers, with best practices and anti-patterns.

Core Features & Use Cases

  • Defines testing foundations, worth testing, and anti-patterns for NestJS projects using TypeORM and PostgreSQL.
  • Includes artifact-specific guidance (entities, services, modules, controllers, guards, strategies, pipes, interceptors, filters, middleware) and references for mock strategies and gotchas.
  • Provides concrete setup patterns for unit, integration, and E2E tests, plus a reproducible structure via artifacts and references.

Quick Start

Use the artifacts and references to implement thorough tests across NestJS modules.

Frequently Asked Questions about testing-guide-nestjs-project

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

FAQPage Schema
How do I structure unit, integration, and e2e tests in a NestJS project?

The best way to test NestJS modules with TypeORM and PostgreSQL is using a layered approach: unit tests for services with mocked dependencies, integration tests for module compilation with external systems mocked, and e2e tests for HTTP contracts. This prevents database flakiness.

What is the correct way to test NestJS guards, pipes, and interceptors?

Testing NestJS guards, pipes, and interceptors requires artifact-specific patterns that validate their integration with the dependency injection container. Use unit tests to isolate logic and mock external dependencies to ensure thorough coverage without hitting the database.

Does this NestJS testing guide apply to projects using Jest 30 and PostgreSQL?

Yes, this NestJS testing guide explicitly applies to projects using NestJS 11, Jest 30, TypeORM, and PostgreSQL. It provides reproducible setup patterns and mock health rules tailored to this specific technology stack for reliable validation.

Why do my NestJS integration tests fail when using a real PostgreSQL database?

NestJS integration tests fail with real databases because they lack proper external system mocks. Enforce mock health rules and isolate module compilation to prevent database state leakage and ensure DI wiring correctness across test runs.

What are common anti-patterns when writing e2e tests for NestJS controllers?

Common e2e testing anti-patterns in NestJS include skipping HTTP contract validation, bypassing middleware, and ignoring DI wiring. Avoid these by following structured artifact-specific guidance to ensure endpoints behave correctly through the entire request cycle.