Express

Supertest request(app)

Integration tests exercise connected components through a realistic boundary. For an Express app, an HTTP test should check the response status, body and important headers. Use app factories and fresh data per test; separate a service unit test from actual routing, parsing and error middleware. Supertest can exercise an Express app and handle its temporary listener. The example requires a reviewed Supertest dependency and Express 5. In a controlled environment test missing records, invalid input and deny cases, not just success. A passing pure assertion below is not evidence that Express is running. Static example only; runtime NOT RUN. Source: https://expressjs.com/en/guide/routing/.

Formal Syntax & Structure

nodejs syntaxnodejs
request(app).get(path).expect(status)

Working Example

Example Snippetnodejs
import express from 'express';import request from 'supertest';import assert from 'node:assert/strict';const app = express();app.get('/health', (req,res) => res.json({ ready: true }));app.use((req,res) => res.sendStatus(404));const response = await request(app).get('/health').expect(200);assert.deepEqual(response.body, { ready: true });await request(app).get('/missing').expect(404);
Node.js Reference