nestjs-unit-tester

Writes and runs Jest unit tests for NestJS services and controllers.

Updated Sep 8, 2026
One-click install
npx skills add https://github.com/lucaszhh/agents --skill nestjs-unit-tester-lucaszhh
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: nestjs-unit-tester
Source: https://github.com/lucaszhh/agents/tree/main/skills/back/nestjs-unit-tester
Command: npx skills add https://github.com/lucaszhh/agents --skill nestjs-unit-tester-lucaszhh

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @nestjs/testing, jest, jest-mock-extended.

What problem does it solve? Writing consistent, high-coverage unit tests for NestJS code is repetitive and error-prone: developers often skip failure paths, forget to reset mocks, or produce fragile tests tied to real implementations. This Skill standardizes spec file creation with TestingModule isolation, typed mocks, and the AAA pattern. ## Core Features & Use Cases - Structured spec generation: Creates *.spec.ts files next to the code under test using an official template with TestingModule, jest-mock-extended typed mocks, and Arrange-Act-Assert structure. - Result pattern validation: Tests both isSuccess and isFailure paths, and verifies controllers map errors to HttpException. - Coverage enforcement: Runs focused coverage with pnpm test -- <spec> --coverage and requires a minimum of 85% on lines and branches. - Use Case: After implementing a new NestJS service, ask the agent to write its unit tests; it writes the spec directly to disk and reports only test signatures and coverage metrics in chat. ## Quick Start Write unit tests with coverage for the demand service in src/modules/demands/domain/services/demand.service.ts.

Frequently Asked Questions about nestjs-unit-tester

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

FAQPage Schema
How do I write unit tests for a NestJS service with Jest?▼

Create a spec file next to the service, build an isolated TestingModule with Test.createTestingModule, and mock every constructor dependency. Structure each test with the Arrange-Act-Assert pattern and clear mocks in beforeEach with jest.clearAllMocks().

How to mock NestJS repository dependencies in unit tests?▼

Use jest-mock-extended to create typed mocks of repository interfaces and provide them via useValue in the TestingModule. This avoids fragile plain-object mocks that break when interfaces change.

What is the AAA pattern in unit testing?▼

AAA stands for Arrange, Act, Assert: first configure inputs and mock responses, then execute the method under test, then verify outcomes with expect(). It keeps each test focused and readable.

How do I test the Result pattern success and failure paths?▼

Assert result.isSuccess is true and check getValue() for happy paths, and assert result.isFailure is true with getError() returning the expected error type like NotFound for failure cases. Controllers should be verified to throw HttpException on failure.

What coverage threshold should NestJS unit tests meet?▼

This workflow enforces a strict minimum of 85% coverage on lines and branches for the file under test. Run pnpm test with --coverage and --collectCoverageFrom targeting the source file to verify the threshold.

When should I not write new unit tests for NestJS code?▼

Skip new tests for cosmetic changes or renames that add no logic, as long as existing assertions still pass. Unit tests are also not the right tool for architecture design or fixing production bugs directly.