with one click
testing-nestjs-applications
Tests NestJS applications at unit, integration, and e2e levels using Test.createTestingModule and Supertest with hand-rolled fakes. Use when writing tests for use cases, controllers, or full HTTP flows.
Menu
Tests NestJS applications at unit, integration, and e2e levels using Test.createTestingModule and Supertest with hand-rolled fakes. Use when writing tests for use cases, controllers, or full HTTP flows.
Defines the rule base every skill in this pack obeys: file layout, frontmatter, vocabulary, OOP/typing/decoupling axioms, and anti-patterns. Load FIRST before authoring or applying any other skill in this pack.
Designs NestJS feature modules with clean dependency boundaries, provider scopes, and dynamic modules. Use when adding a new feature module, splitting a monolithic AppModule, or fixing tangled imports between modules.
Builds thin NestJS controllers that parse input, invoke a single use case, and map the Result to ApiResponse<T>. Use when adding HTTP endpoints, refactoring fat controllers, or applying API versioning.
Prepares a NestJS service for production: graceful shutdown, health/readiness, structured logs, config, Dockerfile, CI gates, and rollout safety. Use when promoting a service to staging/production or auditing readiness.
Designs NestJS application services as use-case classes that orchestrate domain logic and ports without leaking the framework. Use when creating new use cases, refactoring services that mix HTTP/DB/domain, or moving from anemic services to OOP.
Maps internal AppError hierarchy to HTTP responses through a single global exception filter and a Result-to-HttpException helper. Use when adding new error types, fixing inconsistent error responses, or removing scattered try/catch in controllers.
| name | testing-nestjs-applications |
| description | Tests NestJS applications at unit, integration, and e2e levels using Test.createTestingModule and Supertest with hand-rolled fakes. Use when writing tests for use cases, controllers, or full HTTP flows. |
| license | MIT |
Test.createTestingModule with real or fake providersjest.mock for internal modules; only for third-party if neededimport { User } from './user.entity';
describe('User', () => {
it('creates with valid email', () => {
const email = Email.create('test@example.com');
const user = User.create('1', email);
expect(user.id).toBe('1');
});
});
import { Test } from '@nestjs/testing';
import { CreateUserUseCase } from './create-user.use-case';
import { FakeUserRepository } from './fakes/fake-user.repository';
describe('CreateUserUseCase', () => {
let useCase: CreateUserUseCase;
beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [
CreateUserUseCase,
{ provide: 'UserRepository', useClass: FakeUserRepository },
],
}).compile();
useCase = module.get(CreateUserUseCase);
});
it('creates user', async () => {
const result = await useCase.execute({ id: '1', email: 'test@example.com' });
expect(result.success).toBe(true);
});
});
const module = await Test.createTestingModule({
controllers: [UserController],
providers: [CreateUserUseCase, { provide: 'UserRepository', useClass: FakeUserRepository }],
}).compile();
// ❌ jest.mock for internal modules
jest.mock('../../application/user.repository');
Test.createTestingModuleSee reference/test-patterns.md for full patterns.