CodexGuild
skills/ HoangNguyen0403/agent-skills-standard

nestjs-testing

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.

GitHub stars
583
Installs
New
Files scanned
5
Scan passedbackend
Source on GitHub

Security scan

Scan passed

No risky patterns were found in the scanned files.

5 files scannedscanner v1.4.0Nov 23, 2026

Content sha256 3e65e141b9eebe65… — run codexguild_scan_skills after installing to verify your local copy.

Static analysis is a first line of defense, not a guarantee. Read the source

SKILL.md

exact scanned copy

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

  • [BE-TEST-01] Parameterized Tests for Equivalent Cases: Prefer test.each for equivalent inputs or boundary permutations; distinct scenarios may stay separate. Reviewers must not demand test.each rewrites without a behavioral gap.
  • [BE-TEST-02] Ban Brittle DB Mocking & Live DB in Unit Tests (GUARD-NEST-02): No string-matching mocks of raw SQL. In unit-test Test.createTestingModule, ban importing live TypeOrmModule.forRoot, MongooseModule.forRoot, SequelizeModule.forRoot, or PrismaModule. Use getRepositoryToken() or .overrideProvider(); reserve real databases for E2E.
  • [BE-TEST-04] Ban Pass-Through Mocks & Controller Echoes (GUARD-NEST-01): Repositories and services prove contract 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.
  • [BE-TEST-06] Real Guards for Authorization: Never use overrideGuard to prove authorization, tenant isolation, or role 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

  • Setup & Mocks ([BE-TEST-04], GUARD-NEST-02): Test.createTestingModule() with mocked providers; getRepositoryToken() for repositories; never import live database modules.
  • No Controller Echoes (GUARD-NEST-01): Assert validation, guards, interceptors, or transformed response contracts.
  • Pattern & Cleanup: AAA. Call jest.clearAllMocks() in afterEach. Reuse companion test files.
  • TS Hygiene: Apply canonical rule A6 (GUARD-TS-FLOATING-ASSERT, GUARD-TS-CATCH-ONLY, GUARD-TS-CONDITIONAL-ASSERT, GUARD-TS-SELF-MOCK, GUARD-TS-MOCKED-SUT).

E2E Testing

  • Database ([BE-TEST-02]): Real Docker test DB; never mock the DB in E2E.
  • Cleanup: Mandatory — transaction rollback or TRUNCATE in afterEach.
  • App Init: Create in beforeAll, close in afterAll.
  • Guards: .overrideGuard(X).useValue({ canActivate: () => true }) only for isolated business tests where authorization is out of scope; dynamic security tests exercise real guards ([BE-TEST-06]).

Strict TypeScript (MANDATORY)

  • No any: Use typed DTOs, jest.Mocked<T>, or as unknown as T. Never as any.
  • No eslint-disable: Fix the underlying type; verify DTO shapes before writing mock data.
  • Cast Jest matchers: Nested expect.anything() -> expect.anything() as unknown.

Anti-Patterns

  • Stylistic rewrites ([BE-TEST-01]): No test.each demands without a behavioral gap.
  • Brittle DB mocks & live DB in unit tests ([BE-TEST-02], GUARD-NEST-02).
  • Controller & mock echoing ([BE-TEST-04], GUARD-NEST-01).
  • Bypassed guards as security proof ([BE-TEST-06]).
  • No Private Tests: Test via public methods, not service['privateMethod'].
  • No DB Mocks in E2E: Real DB with cleanup; mocks defeat E2E purpose.
  • No Shared State: jest.clearAllMocks() in afterEach; close app and DB in afterAll.

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

Files

5
21.5 KB

Agent reviews

0

No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.

More from HoangNguyen0403/agent-skills-standard8

common-mobile-ux-core

Enforce universal mobile UX principles for touch-first interfaces including touch targets, safe areas, and mobile-specific interaction patterns. Use when building mobile screens, handling touch interactions, or validating safe area compliance.

Scan passed 583 1
react-native-performance

Optimize React Native rendering for smooth 60fps mobile experiences. Use when optimizing React Native app performance, reducing re-renders, or fixing frame drops.

Scan passed 583 1
android-agp-upgrade

Upgrade an Android project to Android Gradle Plugin (AGP) 9. Use when migrating to AGP 9, updating Gradle build files, migrating to built-in Kotlin, or adopting the new AGP DSL.

Scan passed 583New
android-architecture

Apply Clean Architecture layering, modularization, and Unidirectional Data Flow in Android projects. Use when setting up project structure, placing code in layers, configuring feature/core modules, or implementing UDF patterns; defer Compose state and ViewModel/StateFlow implementation to their spec

Scan passed 583New
android-background-work

Implement WorkManager and background processing correctly on Android. Use when creating Worker classes, scheduling tasks, choosing between WorkManager and Foreground Services, or setting up Hilt in workers; defer FCM and notification delivery to android-notifications.

Scan passed 583New
android-compose

Build high-performance declarative UI with Jetpack Compose. Use when writing Composable functions, optimizing recomposition, hoisting state, or working with LazyColumn and side effects; defer deep-link and navigation routing to android-navigation.

Scan passed 583New
android-compose-migration

Migrate an Android XML View to Jetpack Compose following a structured 10-step workflow. Use when converting XML layouts to Compose, setting up Compose in an existing View-based project, or incrementally adopting Compose.

Scan passed 583New
android-concurrency

Write correct coroutine scopes, lifecycle collection, and dispatcher injection in Android production code. Use for suspend functions, coroutine scopes, and dispatcher mechanics; defer ViewModel StateFlow/LiveData architecture, Fragment lifecycle recipes, persistence/notifications, and unit-test reci

Scan passed 583New

Related backend skillsscan passed

mcp-builder

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

Scan passed 188.1K 1
runai-audit-assigned-quota

Audit GPU quota fairness across a Run:ai cluster — find which projects are starved and which are borrowing over their deserved quota in each node pool, and where GPUs can be reclaimed. Use when an admin asks "who is over quota in node-pool X", "which projects are starved", "is the cluster shared fai

Scan passed 3.8KNew
creating-api-gateway-stage

Creates an API Gateway stage with CloudWatch logging, X-Ray tracing, throttling, WAF integration, and IAM roles following AWS best practices. Use when deploying a REST API to different environments such as dev, test, or production.

Scan passed 3.4KNew
qa-only

Report browser/API/CLI/job/worker/webhook bugs. Use for: qa report only, just report bugs, test but dont fix. (gstack)

Scan passed 140.4KNew
mcp-integration

This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context Protocol", "connect external service", mentions "${CLAUDE_PLUGIN_ROOT} with MCP", or discusses MCP server types (SSE, stdio, HTTP, WebSocket). Provides

Scan passed 46.2KNew
cloud-operator-setup

Sets up the user's personal operator agent in a Google Cloud organization via the `ask_cloud_operator` MCP tool (the autocloud server, or any server that offers it): finds the project's organization, checks or creates the agent, saves the project and organization, and offers to share the user's exis

Scan passedNew