nestjs-testing

Automate NestJS unit, integration, and end-to-end tests with Jest.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill nestjs-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nestjs-testing
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-nestjs/skills/nestjs-testing
Command: npx skills add https://github.com/TheBushidoCollective/han --skill nestjs-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a blueprint for testing NestJS applications with unit, integration, and end-to-end tests.

Core Features & Use Cases

  • Unit Testing Modules: Set up TestingModule with providers and mocks.
  • Controller & Service Tests: Mock dependencies and verify behavior.
  • E2E Testing: Integration tests that exercise the full stack.

Quick Start

Scaffold a TestingModule for a UserController with a mocked UserService and verify responses.

Frequently Asked Questions about nestjs-testing

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

FAQPage Schema
How do I set up unit tests for NestJS modules?

Unit testing NestJS modules uses TestingModule to configure providers and mocks. Create a TestingModule with your module's providers, replace real dependencies with mocks, and use Jest to verify module behavior in isolation.

Can I mock TypeORM repositories in NestJS tests?

Yes, mock TypeORM repositories by using getRepositoryToken to inject fake implementations into TestingModule. This allows you to test services that depend on database repositories without touching the database.

How do I test NestJS controllers and services together?

Integration testing validates controller and service interaction by configuring TestingModule with both components, mocking external dependencies, and using Jest spies and assertions to verify request handling and service calls.

What's the best way to test error handling in NestJS?

Test error handling by configuring edge cases in mocked services, triggering exceptions through Jest assertions, and validating that controllers catch and properly respond to errors using TestingModule.

Do I need different test configurations for unit, integration, and e2e tests?

Unit tests use TestingModule with full mocking, integration tests combine multiple modules with selective mocking, and e2e tests exercise the full stack. Each layer requires different TestingModule provider configurations.