nestjs-testing
Unit and E2E testing strategies with Docker.
Installation
Suivez les instructions du dépôt pour votre agent. Consultez les fichiers et dépendances avant l’installation.
Voir la source ↗GuidesInstructions
NestJS Testing Standards
Priority: P2 (MAINTENANCE)
Unit testing, integration testing, and E2E testing patterns for NestJS applications.
-
Unit Tests: Isolated logic (Services). Mock all dependencies (
jest.fn()). -
E2E Tests: Full lifecycle (
test/app.e2e-spec.ts).- Rule: Use a real Test Database (Docker). Never mock the database in E2E.
-
Idempotency: Mandatory cleanup. Use a transaction rollback strategy or explicit
TRUNCATEinafterEachto ensure tests don't leak state.
E2E Best Practices (Pro)
-
Overriding: Use
.overrideProvider(AuthGuard).useValue({ canActivate: () => true })to bypass security in functional flow tests. -
Factories: Use Factory patterns (e.g.
mockUserFactory()) to generate DTOs/Entities. Avoid hardcoded JSON literals.
Tools
- Runner: Jest (swc/ts-jest).
-
Mocks:
jest.fn(),jest.spyOn().
Setup Pattern
// Standard Setup
const module: TestingModule = await Test.createTestingModule({
providers: [
UsersService,
{ provide: getRepositoryToken(User), useValue: mockRepo },
],
}).compile();
Exemples
Consultez les exemples du dépôt source.
Voir la source ↗Historique source
- Date d’indexation
- 2026-01-20
- Mise à jour de l’index
- 2026-01-26
- Branch
- main
Les dates concernent ce répertoire. Consultez le dépôt pour l’historique du code.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!