home / skills / shipshitdev / library / nestjs-testing-expert
This skill helps you build reliable Jest test suites for NestJS modules, services, and controllers with deterministic, fast tests.
npx playbooks add skill shipshitdev/library --skill nestjs-testing-expertReview the files below or copy the command above to add this skill to your agents.
---
name: nestjs-testing-expert
description: Testing patterns for NestJS apps using Jest, covering unit, integration, and e2e tests.
---
# NestJS Testing Expert
You build reliable Jest test suites for NestJS modules, services, and controllers.
## When to Use
- Writing unit or integration tests for NestJS
- Setting up TestModule, mocking providers, or database fakes
- Debugging flaky tests
## Testing Pyramid
- Unit tests for pure logic and services
- Integration tests for modules with real providers
- E2E tests for HTTP APIs
## Common Patterns
- Use `Test.createTestingModule` with explicit providers.
- Mock external services with jest.fn or test doubles.
- For DB: use in-memory adapters or test containers when needed.
- Prefer `supertest` for HTTP-level e2e.
## Tips
- Keep tests deterministic.
- Reset mocks between tests.
- Avoid shared mutable state.
## Checklist
- Clear arrange/act/assert structure
- Minimal mocking
- Covers error paths
- Fast to run
This skill teaches testing patterns and pragmatic workflows for NestJS applications using Jest, covering unit, integration, and end-to-end (E2E) tests. It focuses on building reliable, fast, and deterministic test suites for modules, services, and controllers. The guidance emphasizes clear structure, minimal mocking, and strategies for dealing with databases and external services.
The skill explains how to construct TestModule instances, register explicit providers, and isolate units under test. It demonstrates mocking external dependencies with jest.fn, using in-memory adapters or test containers for database layers, and running E2E tests through supertest against an application instance. It also outlines test lifecycle practices like resetting mocks and avoiding shared mutable state to prevent flakiness.
Should I use real databases in integration tests?
Prefer in-memory adapters or test containers for integration tests; use real databases sparingly and isolate them to avoid brittle CI runs.
How do I prevent test flakiness?
Reset mocks and module state between tests, avoid shared mutable state, and keep tests deterministic by controlling time and async behavior where needed.