sdcorejs-testing-unit-nestjs

Generate NestJS unit tests with mocked dependencies and Test.createTestingModule.

2|Updated Apr 18, 2026
One-click install
npx skills add https://github.com/sdcorejs/sdcorejs-agent --skill sdcorejs-testing-unit-nestjs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sdcorejs-testing-unit-nestjs
Source: https://github.com/sdcorejs/sdcorejs-agent/tree/main/plugin/skills/sdcorejs-testing-unit-nestjs
Command: npx skills add https://github.com/sdcorejs/sdcorejs-agent --skill sdcorejs-testing-unit-nestjs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents regressions in NestJS business logic by producing reliable unit tests that validate outcomes, thrown exception types, and transaction behavior without touching real DBs or networks.

Core Features & Use Cases

  • Unit-test service logic with mocked collaborators: tests one service method with repositories and query runners mocked, including transaction rollback/commit checks.
  • Test mappers and DTO mapping rules: verifies mapping of fields and null-handling in pure mapper functions without brittle snapshots.
  • Test Zod validators with table-driven cases: uses it.each for multiple inputs and confirms bilingual error messages without re-testing Zod itself.
  • Light controller wiring tests: validates controller delegates to service and returns expected results, while pushing heavy logic into the service.

Quick Start

Use sdcorejs-testing-unit-nestjs to write unit tests for a NestJS service method, mapper, or Zod schema after the implementation lands.

Frequently Asked Questions about sdcorejs-testing-unit-nestjs

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

FAQPage Schema
How do I write NestJS unit tests for service logic without hitting a real database?

To write NestJS unit tests without a real database, you mock repository dependencies and QueryRunners using Test.createTestingModule. This isolates business logic, validates transaction rollback behavior, and asserts thrown exception types without network or DB calls.

How do I test Zod validators in NestJS using table-driven cases?

You test Zod validators in NestJS by using the it.each method for table-driven test cases. This approach verifies multiple inputs and confirms bilingual error messages without redundantly testing the Zod library's internal logic.

What is the best way to test transaction rollback behavior in a mocked NestJS service?

The best way to test transaction rollback in a mocked NestJS service is by mocking a QueryRunner object within your test module. This allows you to explicitly assert whether commit or rollback methods are called under specific error conditions.

Can I test NestJS mappers without using brittle snapshot testing?

Yes, you can test NestJS mappers by verifying field mappings and null-handling directly in pure mapper functions. This validates the transformation logic accurately without relying on brittle snapshot comparisons.

Does this approach to unit testing work for thin NestJS controllers?

Yes, this approach provides light controller wiring tests that validate a controller delegates correctly to its service and returns expected results, while ensuring heavy business logic remains pushed into the service layer.

When should I add a failing unit test first in NestJS development?

You should add a failing unit test first when addressing a bug in NestJS business logic. This test-first approach validates the defect, guides the fix, and prevents future regressions after the service method or utility lands.