nestjs-testing-skill

Configure Jest and write unit, integration, and e2e tests for NestJS.

2|Updated Dec 5, 2025
One-click install
npx skills add https://github.com/AgentiveCity/SkillFactory --skill nestjs-testing-skill
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nestjs-testing-skill
Source: https://github.com/AgentiveCity/SkillFactory/tree/main/.claude/skills/nestjs-testing-skill
Command: npx skills add https://github.com/AgentiveCity/SkillFactory --skill nestjs-testing-skill

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Setting up, writing, and refactoring tests for NestJS TypeScript backends (unit, integration, e2e) with Jest, TestingModule, and Supertest can be complex and time-consuming. This Skill automates the testing process, ensuring application reliability, maintainability, and reducing manual effort.

Core Features & Use Cases

  • Comprehensive Test Setup: Configure Jest for NestJS, including root and e2e configurations, and define package.json scripts for running tests.
  • Unit & Controller Test Generation: Write or refactor unit tests for services, guards, pipes, and controllers using Nest's TestingModule and mocked dependencies.
  • End-to-End API Validation: Implement e2e tests using Supertest to bootstrap the full Nest application and hit real HTTP endpoints, including auth-protected routes.

Quick Start

Write unit tests for this NestJS service, add e2e tests for our auth routes in Nest, and mock TypeORM repositories in my Nest tests.

Frequently Asked Questions about nestjs-testing-skill

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

FAQPage Schema
How do I set up Jest and TestingModule for NestJS unit tests?

Jest configuration for NestJS involves setting up a root jest.config.js with TypeScript support and defining a TestingModule via NestJS's Test.createTestingModule() to instantiate services with mocked dependencies. This creates an isolated test environment matching your application structure.

How do I write end-to-end tests for NestJS API endpoints?

End-to-end testing with Supertest bootstraps your full NestJS application and makes real HTTP requests to validate routes and responses. You initialize the app, use Supertest's request methods (e.g., .get(), .post()), and assert on status codes and payloads without mocking the application layer.

Can I mock TypeORM repositories in NestJS tests?

Yes, use NestJS's getRepositoryToken() to inject mocked repositories into your TestingModule. This pattern allows you to stub database calls in unit and integration tests while maintaining the same dependency injection structure as production code.

What's the best way to test NestJS guards and pipes?

Test guards and pipes using TestingModule to instantiate them directly or inject them into controllers and services you're testing. Mock their dependencies (e.g., Reflector for guards, validation schemas for pipes) and verify their execute() or transform() methods with controlled inputs.

Do I need separate Jest configs for unit and e2e tests in NestJS?

Yes, maintaining separate jest.config.js for unit tests and jest-e2e.config.js for end-to-end tests avoids conflicts. Unit tests target individual services with mocks; e2e tests bootstrap the full application. Use distinct test file patterns and scripts in package.json to run each suite independently.