Keploy logo
NestJS logo

Keploy as a NestJS testing framework

Keploy tests NestJS applications by recording real requests through the running HTTP server and every database or outbound call they trigger, then replaying both as assertions. There is no Test.createTestingModule graph to assemble and no provider to override.

Generate NestJS tests free
keploy record -c "node dist/main.js"
18.4K+VS Code1.2M+300M+mocks created

What Keploy gives a NestJS team

Any NestJS app, unchanged

Keploy runs the compiled entrypoint. Express and Fastify adapters, microservice transports, and GraphQL resolvers all record the same way because capture happens at the socket rather than inside the DI container.

  • NestJS 9 and above
  • Express or Fastify adapter
  • REST, GraphQL, and gRPC
  • Modules initialise for real
The problem

Why NestJS integration tests slow teams down

The friction is rarely the assertions. It is everything around them — spinning up dependencies, keeping mocks honest, and repairing tests after every refactor.

Three ways to do it

Testing NestJS: by hand, with Jest + createTestingModule, or with Keploy

createTestingModule rebuilds the container with providers swapped out. Keploy records the running app, so guards, interceptors, pipes, and the real provider chain all execute.

Select any row for the full comparison, with code.

Same coverage, three costs

What you write for NestJS vs what Keploy records

All three produce the same assertion. Only the third still passes after the next refactor without anyone editing it.

By hand2–4 hours
orders.controller.spec.ts
hand-written
// Hand-written: the controller is called past guards and pipes.
import { OrdersController } from './orders.controller';
 
const fakeRepo = {
findOne: async () => ({ id: 'ord_1', amountMinor: 4200, state: 'NEW' }),
save: async (order) => order,
};
 
const fakePayments = {
authorize: async () => ({ status: 'AUTHORIZED' }),
};
 
describe('OrdersController', () => {
it('confirms an authorized order', async () => {
const controller = new OrdersController(fakeRepo as any, fakePayments as any);
 
const result = await controller.confirm('ord_1', { paymentToken: 'tok_123' });
 
expect(result.state).toBe('CONFIRMED');
});
});

Two casts to any and two hand-written doubles. The auth guard, validation pipe, and response interceptor never run.

Jest + createTestingModule1–2 hours
orders.e2e-spec.ts
tool-assisted
// Jest + createTestingModule + supertest.
import { Test } from '@nestjs/testing';
import request from 'supertest';
import nock from 'nock';
 
let app;
 
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [AppModule],
})
.overrideProvider(PaymentsService)
.useValue({ authorize: async () => ({ status: 'AUTHORIZED' }) })
.compile();
 
app = moduleRef.createNestApplication();
await app.init();
});
 
it('confirms an authorized order', async () => {
const res = await request(app.getHttpServer())
.post('/orders/ord_1/confirm')
.send({ paymentToken: 'tok_123' });
 
expect(res.status).toBe(200);
});

Drives the real pipeline — but PaymentsService is overridden, so the one integration this test is named for never actually happens.

With Keploy~5 minutes
test-1.yaml
auto-generated
# Recorded with: keploy record -c 'node dist/main.js'
# Real container. Real guards. No overrides.
version: api.keploy.io/v1beta1
kind: Http
name: test-1
spec:
req:
method: POST
url: /orders/ord_1/confirm
header:
Authorization: Bearer <captured>
body: '{"paymentToken":"tok_123"}'
resp:
status_code: 200
body:
id: "ord_1"
state: "CONFIRMED"
amountMinor: 4200
confirmedAt: "2026-09-02T11:04:18Z"
noise:
- body.confirmedAt
mocks:
- kind: Postgres
operation: 'SELECT "o"."id", "o"."amount_minor", "o"."state" FROM "orders" "o" WHERE "o"."id" = $1'
- kind: Http
url: https://api.payments.example.com/v1/payment_intents/tok_123/confirm
status: 200

The guard authorised this request, the pipe validated the body, and the real PaymentsService made the call — all captured, none overridden.

Times are estimates for authoring one endpoint’s coverage from scratch, not measurements.

Keploy vs the alternatives

NestJS testing tools, compared

The options a team on Node.js actually reaches for, and where each one genuinely wins. Select a row for the full comparison.

Best in classStrongPartialNot covered

Assessments reflect each tool’s documented behaviour, not benchmark measurements.

How it works

Record your NestJS app once, replay it forever

Keploy sits below your NestJS process at the network layer. It watches the calls your app already makes, then serves them back on replay so tests run with no dependencies attached.

Keploy records a GET call to /api/v1/orders/{id} on a NestJS service and captures the dependency calls it makes.

An example shape of a captured call. Your own endpoints and dependencies come from your real traffic, so nothing here has to be written by hand.
Quick start

Your first NestJS test suite in under five minutes

Every command below runs against your existing NestJS service. Nothing in your source tree changes.

  1. 1Install the Keploy CLI

    A single binary. It needs a Linux kernel with eBPF support, or Docker on macOS and Windows — and it adds nothing to your project's dependencies.

    curl -sSL https://keploy.io/install.sh | bash
  2. 2Record your service

    Pass the command you already use to start the app. Keploy runs it and watches every socket it opens.

    keploy record -c "node dist/main.js"
  3. 3Exercise the paths you care about

    Build as normal, then drive the running app. Every request becomes a test case with its database and HTTP calls captured alongside.

    npm run build
    curl -X POST localhost:3000/orders/ord_1/confirm -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN' -d '{"paymentToken":"tok_123"}'
  4. 4Replay in CI

    Replay serves the recorded dependency responses, so the job needs no service containers and no Docker daemon.

    keploy test -c "node dist/main.js" --delay 10

Ready to try it on your own NestJS service?

Ecosystem

Works with the rest of your NestJS stack

Keploy records at the network layer, so framework and driver choices inside your NestJS app do not change how it captures traffic.

FAQ

NestJS testing with Keploy: common questions

Join our GlobalCommunity

Connect with developers worldwide. Follow updates, ask questions, share feedback, and ship faster with other Keploy builders.

1.2M+Installs
18.4K+GitHub
100K+Devs
300M+Mocks
1K+Contributors
#1OSS Trending
4.9★★★★★from 500+ reviews onG2GartnerVS CodeChrome
★★★★★

Best report of integration and API tests I've seen — which we don't get from RestAssured.

G2
★★★★★

Future of microservices testing. I don't write tests now!

G2 · 5/5
★★★★★

An amazing product that simplifies the automation.

Gartner · 4.0
XGitHubSlackYouTubeLinkedIn
Built by developers, for developers.Let's build the future, together.