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.
- 01GitHub stars
- 583
- 02Installs
- New
- 03Files scanned
- 5
Security scan
Scan passedNo risky patterns were found in the scanned files.
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
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: Prefertest.eachfor equivalent inputs or boundary permutations; distinct scenarios may stay separate. Reviewers must not demandtest.eachrewrites 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-testTest.createTestingModule, ban importing liveTypeOrmModule.forRoot,MongooseModule.forRoot,SequelizeModule.forRoot, orPrismaModule. UsegetRepositoryToken()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 useoverrideGuardto 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()inafterEach. 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
TRUNCATEinafterEach. - App Init: Create in
beforeAll, close inafterAll. - 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>, oras unknown as T. Neveras 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]): Notest.eachdemands 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()inafterEach; close app and DB inafterAll.
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- SKILL.md
fb18d021ca4.3 KB - evals/evals.json
2a56f2c2d02.1 KB - references/improve-coverage.md
df137064102.4 KB - references/patterns.md
8ca2650d606.5 KB - references/strict-typescript-testing.md
3ccfd19ac36.2 KB
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from HoangNguyen0403/agent-skills-standard8
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.
Optimize React Native rendering for smooth 60fps mobile experiences. Use when optimizing React Native app performance, reducing re-renders, or fixing frame drops.
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.
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
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.
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.
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.
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
Related backend skillsscan passed
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).
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
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.
Report browser/API/CLI/job/worker/webhook bugs. Use for: qa report only, just report bugs, test but dont fix. (gstack)
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
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