AgentSkillsCN

nestjs-testing

掌握NestJS测试技能,熟练运用Jest与Supertest。该功能将在以下场景中自动触发: - 为NestJS应用编写或生成测试文件时; - 为NestJS项目配置Jest测试环境时; - 调试单元测试、集成测试或端到端测试的失败案例时; - 创建测试工厂、模拟对象或测试辅助工具时; - 提升NestJS服务、控制器或用例的测试覆盖率时; - 为HTTP端点编写Supertest端到端测试时; - 在测试中模拟Mongoose模型或仓储层时; - 为集成测试配置mongodb-memory-server时。

SKILL.md
--- frontmatter
name: nestjs-testing
description: |
  NestJS testing skill with Jest and Supertest. Automatically invoked when:
  - Writing or generating test files for NestJS applications
  - Setting up Jest configuration for a NestJS project
  - Debugging failing tests (unit, integration, or e2e)
  - Creating test factories, mocks, or test helpers
  - Improving test coverage for NestJS services, controllers, or use cases
  - Writing Supertest e2e tests for HTTP endpoints
  - Mocking Mongoose models or repositories in tests
  - Setting up mongodb-memory-server for integration tests
allowed-tools: Read, Write, Edit, Bash, Glob, Grep

NestJS Testing Skill

This skill provides patterns, utilities, and templates for writing comprehensive tests in NestJS using Jest and Supertest.

Quick Reference

  • For unit test patterns → read references/unit-testing.md
  • For e2e / Supertest patterns → read references/e2e-testing.md
  • For mocking helpers → read references/mocking.md
  • To generate a test file → run scripts/generate-test.sh <path-to-source-file>

Test File Location Convention

Source fileTest file
src/domain/entities/user.entity.tssrc/domain/entities/user.entity.spec.ts
src/application/use-cases/create-user.use-case.tssrc/application/use-cases/create-user.use-case.spec.ts
src/infrastructure/database/repositories/mongoose-user.repository.tssrc/infrastructure/database/repositories/mongoose-user.repository.spec.ts
src/presentation/controllers/users.controller.tstest/users.e2e-spec.ts

Coverage Targets

  • Domain entities: 100%
  • Use cases: 100%
  • Repository implementations: ≥ 90%
  • Controllers: tested via e2e only