사용 방법
- 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
- 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
- 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
npx skills add https://github.com/j4flmao/agent_skills_nodejs_nestjs --skill testing-nestjs-applications시작 전 확인
- 설치에는 모델 구독, API 한도, 파일 접근 권한이 포함되지 않습니다.
- 별점 수와 설치 수는 활동 지표이며 독립적인 품질·보안 검증이 아닙니다.
원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.
Testing NestJS Applications
When to use
- Writing tests for use cases, controllers, or full HTTP flows
- Setting up test strategy for a NestJS feature
- Replacing mocks with hand-rolled fakes
Core rules
- Unit tests: domain entities with pure assertions (no NestJS testing module)
- Use-cases tested with hand-rolled fakes (not jest.mock)
- Integration tests:
Test.createTestingModulewith real or fake providers - E2E tests: Supertest against bootstrapped app
- No
jest.mockfor internal modules; only for third-party if needed
Reference shape (TypeScript)
Unit Test (Domain Entity)
import { 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');
});
});Integration Test (Use-Case with Fake)
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);
});
});Examples — Do
const module = await Test.createTestingModule({
controllers: [UserController],
providers: [CreateUserUseCase, { provide: 'UserRepository', useClass: FakeUserRepository }],
}).compile();Examples — Don't
// ❌ jest.mock for internal modules
jest.mock('../../application/user.repository');Checklist
- [ ] Domain entities have unit tests
- [ ] Use-cases tested with hand-rolled fakes
- [ ] Integration tests with
Test.createTestingModule - [ ] E2E tests with Supertest
See reference/test-patterns.md for full patterns.



