API Integration Tests with Supertest
We develop API integration tests for Node.js applications using Supertest, giving your team reliable automated coverage of all REST endpoints. Our engineers write test suites for Express, Fastify, and NestJS backends, covering authentication flows, error handling, pagination, file uploads, and webhook processing. We have written API test suites for 30+ Node.js services. Our clients ship with confidence knowing every endpoint has automated coverage, and regressions are caught before they reach production users.
Supertest lets you test HTTP endpoints directly through your application instance without starting a real server. Tests run fast, integrate with Jest or Mocha, and catch regressions before they reach production. A well-written API test suite pays for itself after the first prevented outage.
What's Included in Our API Tests Development Service
We deliver complete API test coverage as a turnkey service. The scope includes:
- Test environment configuration: database setup, seed data, teardown strategy
- Authentication helper utilities for token-based and session-based flows
- Endpoint tests covering happy paths and all documented error states
- File upload and multipart form testing
- Pagination and filtering parameter tests
- Integration with CI pipeline so tests block deployments on failure
- Test coverage report with gap analysis and recommendations
Why Choose Supertest for API Testing?
Supertest sits between unit tests and end-to-end tests. It tests your actual HTTP layer, middleware, validation, and database interactions together, without the overhead of a running server or a real network. This makes it faster and more deterministic than end-to-end tools like Cypress or Playwright for pure API testing.
For teams that already use Jest, adding Supertest requires minimal setup. Tests look like familiar assertions, the learning curve is low, and the feedback loop is fast. Our clients typically achieve 80-90% endpoint coverage within the first week of implementation.
Installation and Basic Setup
npm install -D supertest @types/supertest
Sample Test Suite
import request from 'supertest';
import { app } from '../../src/app';
import { db } from '../../src/database';
beforeAll(async () => await db.migrate.latest());
afterAll(async () => await db.destroy());
afterEach(async () => await db('users').truncate());
describe('POST /api/auth/login', () => {
beforeEach(async () => {
await request(app).post('/api/users').send({
email: '[email protected]',
password: 'password123',
name: 'Test User',
});
});
it('returns 200 and token on valid credentials', async () => {
const res = await request(app)
.post('/api/auth/login')
.send({ email: '[email protected]', password: 'password123' })
.expect(200);
expect(res.body.access_token).toBeDefined();
expect(res.body.user.email).toBe('[email protected]');
});
it('returns 401 on wrong password', async () => {
await request(app)
.post('/api/auth/login')
.send({ email: '[email protected]', password: 'wrongpass' })
.expect(401);
});
});
How Are Authorized Requests Tested?
export async function getAuthToken(app: Express): Promise<string> {
const res = await request(app)
.post('/api/auth/login')
.send({ email: '[email protected]', password: 'adminpass' });
return res.body.access_token;
}
describe('Products API', () => {
let token: string;
beforeAll(async () => {
token = await getAuthToken(app);
});
it('creates product with auth', async () => {
const res = await request(app)
.post('/api/products')
.set('Authorization', `Bearer ${token}`)
.send({ name: 'MacBook Pro', price: 150000, slug: 'macbook-pro' })
.expect(201);
expect(res.body.id).toBeDefined();
});
it('returns 401 without auth', async () => {
await request(app).post('/api/products').send({ name: 'Test' }).expect(401);
});
});
NestJS Integration
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
describe('UsersController', () => {
let app: INestApplication;
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleRef.createNestApplication();
await app.init();
});
afterAll(async () => await app.close());
it('GET /users returns array', () => {
return request(app.getHttpServer()).get('/users').expect(200)
.expect(res => expect(Array.isArray(res.body)).toBeTruthy());
});
});
Delivery Process
Our team follows a four-step process for every API tests engagement:
- Audit your existing endpoints and identify which ones carry the most business risk
- Set up the test environment with database migrations, seed fixtures, and teardown logic
- Write tests for all endpoints, prioritizing auth flows and data-mutating operations
- Integrate the test suite with your CI pipeline and document the coverage baseline
| Scope | Timeline |
|---|---|
| 10–15 endpoints, single auth flow | 2–3 working days |
| 20–30 endpoints with file upload and pagination | 4–5 working days |
| Full API surface with NestJS and custom auth | 5–7 working days |
We deliver well-structured, maintainable tests. Contact us to get a quote based on your API documentation or Swagger spec. Our team will review it and send a detailed proposal within one business day.
CI Pipeline Integration
Tests that only run locally provide weak protection. We configure Supertest suites to run automatically on every pull request via GitHub Actions, GitLab CI, or your existing CI tool. A failing test blocks the merge until the issue is resolved.
# .github/workflows/api-tests.yml
jobs:
test:
services:
postgres:
image: postgres:15
env:
POSTGRES_DB: test_db
POSTGRES_USER: test
POSTGRES_PASSWORD: test
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm test
env:
DATABASE_URL: postgresql://test:test@localhost/test_db
We configure the test database to reset between runs using migrations, and seed only the minimal fixture data each specific test requires.
How We Deliver
We audit your existing endpoints. We identify the highest-risk flows. We set up the test environment. We write authentication helpers. We cover happy paths first. We add all error case tests. We configure CI integration. We document the coverage baseline. We hand over the suite with a gap analysis report.







