Supertest
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."
Related Terms
Jest
Jest is the most popular JavaScript testing framework.
Testcontainers
Instead of mocking your database in tests, Testcontainers spins up a REAL database in a Docker container, runs your tests against it, then throws it away.
WireMock
WireMock pretends to be an API so your tests don't need the real thing. Need to test what happens when Stripe returns an error? WireMock fakes it. It's lik