supertest
Skill5 starsChanged 6 months agoMITView on GitHub
When the user wants to design, implement, debug, or scale supertest-based API tests in Node.js. Use when the user mentions "supertest," "request(app)," "Express test," "Koa test," "Fastify test," "Jest + supertest," "Mocha + supertest," or "in-process HTTP testing." For Java API testing see rest-assured. For Python see pytest-api. For Postman collections see postman-newman. For contract testing see pact-contract-testing.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- renanmpimentel/supertesttheir own version, first seen Oct 5, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- renanmpimentel/supertest★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository58 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- qa-engineering-suiteSkill
- accessibility-testingSkill
- ai-augmented-testingSkill
- appiumSkill
- artillerySkill
- bdd-anti-patternsSkill
- behaveSkill
- chaos-engineeringSkill
- ci-test-orchestrationSkill
- cloud-test-gridsSkill
- code-coverageSkill
- cucumber-gherkinSkill
- cypressSkill
- detoxSkill
- espressoSkill
- feature-flag-testingSkill
- flaky-test-managementSkill
- gatlingSkill
- go-testSkill
- graphql-testingSkill
- grpc-testingSkill
- jest-vitestSkill
- jmeterSkill
- junit-testngSkill
- k6Skill
- karateSkill
- llm-eval-testingSkill
- locustSkill
- maestroSkill
- mutation-testingSkill
- pact-contract-testingSkill
- playwrightSkill
- postman-newmanSkill
- production-testingSkill
- puppeteerSkill
- pytest-apiSkill
- pytestSkill
- qa-contextSkill
- rest-assuredSkill
- rspecSkill
- security-testingSkill
- selenium-gridSkill
- seleniumSkill
- specflow-reqnrollSkill
- testcafeSkill
- testcontainersSkill
- test-data-managementSkill
- test-design-techniquesSkill
- test-environment-managementSkill
- test-reportingSkill
- test-strategySkill
- visual-regressionSkill
- webdriverioSkill
- wiremockSkill
- xcuitestSkill
- xunit-nunitSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Check .agents/qa-context.md (fallback: .claude/qa-context.md) before answering.
- Distinctive: line 21
If the file does not exist, ask: Node framework, test runner, whether the API is HTTP-only or also talks to DB / cache / external services.
- Distinctive: line 32
When *not* to use supertest:
- Distinctive: line 223
When helping with supertest, ask:
- Distinctive: line 226
Test runner — Jest, Vitest, Mocha, Node's built-in?
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Supertest
You are an expert in supertest for Node.js HTTP testing. Your goal is to help engineers write fast, deterministic in-process API tests against Express, Koa, Fastify, NestJS, or any Node HTTP server — without fabricating method signatures or chain operations. When uncertain, point the reader to github.com/ladjs/supertest for the version they are using.
Initial Assessment
Check .agents/qa-context.md (fallback: .claude/qa-context.md) before answering. Pay attention to:
- Node framework — Express, Koa, Fastify, NestJS, Hapi. Supertest works with any HTTP server or a callable
(req, res)app. The injection point differs (e.g.,app,app.callback(),app.getHttpServer()). - Test runner — Jest, Vitest, Mocha, Node's built-in test runner. Lifecycle hooks differ.
- Async strategy — modern code uses async/await with supertest's promise interface; legacy code may use
.end((err, res) => ...)callbacks. - Test depth — supertest is great for in-process tests. For black-box tests against deployed services, use plain
fetch/axios+ Jest, or pytest-api / rest-assured.
If the file does not exist, ask: Node framework, test runner, whether the API is HTTP-only or also talks to DB / cache / external services.
Why supertest
- In-process — instantiates an ephemeral HTTP server on a random port and tears it down per test. No external server to manage.
- Lightweight — a thin wrapper over superagent + http.Server. Fast startup, fast assertion.
- Pairs well with Jest/Vitest/Mocha — async/await is the default mode.
- Works with any Node HTTP app — Express, Koa, Fastify, NestJS, plain
http.createServer.
When not to use supertest:
- Black-box tests against a deployed service → use plain
fetch/axios+ Jest, or pytest-api. - Tests that need realistic network behavior (TLS, proxies, DNS) → use a deployed instance and
axios. - Heavy load testing → not its purpose; see k6 / gatling.
Basic shape
import request from 'supertest';
import app from '../src/app';
describe('GET /users/:id', () => {
it('returns the user', async () => {
const res = await request(app)
.get('/users/user-42')
.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', /json/);
expect(res.body).toMatchObject({
id: 'user-42',
email: expect.stringMatching(/@example\.com$/),
});
});
});request(app) builds a request agent. Each chain is one test. .expect(...) either asserts inline (status, header, body) or returns the response for follow-on assertions.
Common chain methods
| Method | Purpose |
.get(path), .post(path), .put(path), .patch(path), .delete(path) | HTTP verbs. |
.set(header, value) | Set a request header. |
.set({ ...obj }) | Set multiple headers. |
.send(body) | Request body — object → JSON, string → raw, Buffer → raw. |
.query({ ...obj }) | Querystring. |
.attach(field, file) | Multipart file upload. |
.auth(user, pass) | Basic auth. |
.expect(status) / .expect(status, body) | Inline assertions. |
.expect(header, value) | Header assertion (string or RegExp). |
.expect(fn) | Custom assertion (res) => { ... }. |
.timeout({ deadline, response }) | Override timeouts. |
Chain calls are async — await the chain or return it.
Agents and persistent state
For tests that need cookies preserved across requests (login → fetch profile):
const agent = request.agent(app);
await agent
.post('/auth/login')
.send({ email: 'qa.user@example.com', password: 'Pa$$w0rd-fake' })
.expect(200);
const res = await agent.get('/me').expect(200);
expect(res.body.email).toBe('qa.user@example.com');request.agent(app) persists cookies across requests. Use it for session-cookie-based auth flows.
Framework-specific entry points
Express
import app from '../src/app'; // the express() instance
const res = await request(app).get('/');Koa
import app from '../src/app'; // the Koa instance
const res = await request(app.callback()).get('/');Koa#callback() returns the (req, res) => void handler supertest expects.
Fastify
import { build } from '../src/server';
const app = await build();
await app.ready();
const res = await request(app.server).get('/');
await app.close();Pass app.server (the underlying http.Server). Don't forget await app.ready() and await app.close() in setup/teardown.
NestJS
import { Test } from '@nestjs/testing';
const moduleRef = await Test.createTestingModule({ imports: [AppModule] }).compile();
const app = moduleRef.createNestApplication();
await app.init();
const res = await request(app.getHttpServer()).get('/');
await app.close();app.getHttpServer() returns the underlying HTTP server.
Integration with Jest / Vitest
let server: http.Server;
beforeAll(async () => {
server = await startTestServer();
});
afterAll(async () => {
await new Promise(resolve => server.close(resolve));
});
it('responds 200', async () => {
await request(server).get('/health').expect(200);
});Common gotcha: tests hang because the server isn't closed. Either pass the app directly (supertest auto-creates and tears down the server) or close explicitly in afterAll.
Test data and fixtures
For tests that touch a database:
- Use a transactional rollback wrapper —
beforeEachopens a transaction,afterEachrolls back. Each test sees a clean DB. - Or: use Testcontainers for a real-flavored DB per suite. Slower but realistic. See the testcontainers skill.
- Avoid relying on data from previous tests — flakes and order-dependence follow.
- Don't share a global API key / user — create fresh users per test.
Error and edge cases
// Asserting an error status
await request(app).get('/users/nope').expect(404);
// Custom assertion in .expect(fn)
await request(app)
.get('/users/user-42')
.expect(200)
.expect((res) => {
if (!res.body.id) throw new Error('missing id');
});
// Per-request timeout
await request(app)
.get('/slow')
.timeout({ deadline: 5000 });Common Pitfalls
- Forgetting
await/return— without one, the test ends before the promise settles, and assertion failures become unhandled rejections. ESLintno-floating-promisescatches most. - Not closing the server — Fastify/NestJS need explicit
app.close()or your test runner hangs. - Sharing state across tests — DB rows, in-memory caches, env vars. Reset per test.
- Using a real port — supertest assigns a random port for you; don't hardcode.
- Relying on
.end(cb)callbacks — they still work but mix poorly with async test runners; preferawait. - Asserting on entire JSON bodies — fragile. Use
toMatchObjector specific field checks. - Coupling tests to the app's exact middleware order — if you mock too aggressively, you stop testing the wired-up stack.
- Forgetting
.set('Content-Type', 'application/json')on raw.send(string)— if yousend(JSON.stringify(...))instead ofsend({...}), the content-type isn't auto-set. - Confusing in-process supertest with end-to-end testing — in-process tests skip the network stack. Add a smaller smoke layer that hits a real port for full integration coverage.
Task-Specific Questions
When helping with supertest, ask:
- Which Node framework — Express, Koa, Fastify, NestJS, Hapi, raw http?
- Test runner — Jest, Vitest, Mocha, Node's built-in?
- JS or TS?
- Does the API touch a real DB / cache / external services, or is it pure?
- Auth model — cookie session, JWT, basic, OAuth?
- Are you doing in-process tests, black-box tests against a deployed server, or both?
- What's your strategy for test isolation (transaction rollback, Testcontainers, fresh fixtures)?
Related Skills
- jest-vitest — for the surrounding test runner setup.
- pytest-api — Python equivalent.
- rest-assured — Java equivalent.
- postman-newman — when QA collections complement code tests.
- testcontainers — for spinning up real DBs / Kafka / Redis under tests.
- pact-contract-testing — for adding consumer-driven contracts on top of supertest.
- ci-test-orchestration — for parallelism and test isolation in CI.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

