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…
от HoangNguyen0403★ 598 звёзд на GitHubОб этом скилле
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
Установить nestjs-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл 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.
Как установить скилл nestjs-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл nestjs-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic