Loading...
Loading...
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.
npx skill4agent add j4flmao/agent_skills_nodejs_nestjs testing-nestjs-applicationsTest.createTestingModulejest.mockimport { 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.createTestingModule