Skip to content

Supertest

Easy — everyone uses thisTesting

ELI5 — The Vibe Check

Supertest lets you test your API endpoints without starting a server. It's like being able to taste-test a restaurant's food without the restaurant actually being open. You send fake HTTP requests to your Express/Fastify app and check what comes back. Simple, clean, and no port conflicts.

Real Talk

A Node.js library for testing HTTP endpoints by providing a high-level abstraction over superagent. It can bind to an Express/Koa/Fastify app instance directly (no running server needed) and offers fluent assertions for status codes, headers, and response bodies in integration tests.

Show Me The Code

import request from 'supertest';
import app from './app';

test('GET /api/users returns 200', async () => {
  const res = await request(app)
    .get('/api/users')
    .expect(200)
    .expect('Content-Type', /json/);
  expect(res.body).toHaveLength(5);
});

When You'll Hear This

"Supertest calls our Express API and asserts the response without spinning up a real server." / "We use Supertest with Jest for API integration tests — each test gets a fresh app instance."

Made with passive-aggressive love by manoga.digital. Powered by Claude.