金色时刻 · 15:48
让好资源,触手可及
AGENT SKILL

testing

testing 是面向测试与安全、开发运维、软件开发的 Agent Skill,来自 HoangNguyen0403/agent-skills-standard。查看技能说明、操作步骤与使用约定,并通过原项目了解详细用法。

Unit and E2E testing strategies with Docker.

SKILL.md

下载 MD ↓
nameNestJS Testing
descriptionUnit and E2E testing strategies with Docker.
metadata{"labels": ["nestjs", "testing", "jest", "e2e"], "triggers": {"files": ["**/*.spec.ts", "test/**"], "keywords": ["Test.createTestingModule", "supertest", "jest"]}}

NestJS Testing Standards

Priority: P2 (MAINTENANCE)

Unit testing, integration testing, and E2E testing patterns for NestJS applications.

  1. Unit Tests: Isolated logic (Services). Mock all dependencies (jest.fn()).
  2. 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 TRUNCATE in afterEach to 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();

来源:HoangNguyen0403/agent-skills-standard · MIT 许可 · 许可原文 · MD 为来源页保存的历史版本