Nestjs testing

From HoangNguyen0403/agent-skills-standard · View interactive version

Nestjs testing is an AI agent skill from the GitHub repository HoangNguyen0403/agent-skills-standard. Write Unit and E2E tests with Jest, mocking strategies, and database isolation in NestJS. Use when writing NestJS unit tests, E2E tests with supertest, or mock providers.

How to use this skill

Skill file

NestJS Testing

**Priority: P2 (MEDIUM)**

Universal anti-slop rules (identity fixtures, tautologies, skip/focus, mock echoing, bug-first lock, sleeps, shallow

assertions, coverage): anti-slop-rules.md. Only NestJS deltas

follow.

Core Rule Anchors

permutations; distinct scenarios may stay separate. Reviewers must not demand test.each rewrites without a behavioral gap.

unit-test Test.createTestingModule, ban importing live TypeOrmModule.forRoot, MongooseModule.forRoot,

SequelizeModule.forRoot, or PrismaModule. Use getRepositoryToken() or .overrideProvider(); reserve real databases

for E2E.

compliance and error mapping. In controller unit tests, ban 1:1 equality with mocked service returns; test validation

pipes, guards, interceptors, or HTTP response shapes.

security. Dynamic security tests execute real guard logic with synthetic test identities.

Structure

src/**/*.spec.ts      # Unit tests (isolated logic)
test/**/*.e2e-spec.ts # E2E tests (full app flows)

Unit Testing

for repositories; never import live database modules.

GUARD-TS-CONDITIONAL-ASSERT, GUARD-TS-SELF-MOCK, GUARD-TS-MOCKED-SUT).

E2E Testing

out of scope; dynamic security tests exercise real guards ([BE-TEST-06]).

Strict TypeScript (MANDATORY)

Anti-Patterns

References

Setup examples, mocking patterns, E2E flows, test builders, coverage config:

references/patterns.md

Strict-TypeScript patterns (Jest matchers, mock typing, DTO verification):

references/strict-typescript-testing.md

Dynamic API security, fuzz testing, and authorization verification:

../../quality-engineering/quality-engineering-api-fuzz-testing/SKILL.md

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.