Write NestJS unit and E2E tests
nestjs-testingskillsetup L2★503
HoangNguyen0403/agent-skills-standard ↗What it does
Write unit and E2E tests for NestJS with Jest mocking
Best for
Writing isolated NestJS unit tests with mocked providers and E2E tests with supertest for API validation.
Inputs
- · NestJS application with services/controllers
- · Jest configuration and supertest installed
Outputs
- · src/**/*.spec.ts unit tests (isolated logic, mocked dependencies)
- · test/**/*.e2e-spec.ts E2E tests (full app flows with Test.createTestingModule)
- · Mock provider definitions and database isolation patterns
Requires
- · Jest test runner
- · supertest for HTTP assertions
- · Test.createTestingModule from @nestjs/testing
Preconditions
- · NestJS project initialized with nest new
- · Jest configuration in nest.config.js or jest.config.js
- · Dependencies installed (npm install)
Failure modes
- · Missing mock provider: createTestingModule fails, add to { provide, useValue } array
- · Database connection in test: breaks isolation, mock the repository instead
- · Shared test state: mocks leak between tests, call jest.clearAllMocks() in afterEach
Trust signals
- · Test.createTestingModule isolates dependencies via mocking
- · AAA pattern (Arrange-Act-Assert) enforced
- · jest.clearAllMocks() between tests prevents state leakage