Supertest

noun

say it: “SOO-per-test” /ˈsupərˌtɛst/

A Node testing package that sends requests to a web app from inside a test, with no server running, and checks the answers.

What is Supertest?

Supertest is a testing package that sends HTTP requests straight to your app, such as an Express app, with no server running. Your test then checks the answer's status, headers and body.

import { test } from "node:test";
import assert from "node:assert/strict";
import request from "supertest";
import { app } from "./app.js";

test("GET /tickets answers 200", async () => {
  const res = await request(app).get("/tickets");
  assert.equal(res.status, 200);
});

In a sentence

  • “With Supertest, the concert tickets tests call GET /tickets without starting the server.”
  • “Lena's test used Supertest to check that a ticket that doesn't exist answers 404.”

Level: Journeyman · More Node.js terms at this level

Updated