/quality-skills:supertestfrom quality-skills
Designs, implements, debugs, and scales supertest-based in-process API tests for Node.js HTTP servers (Express, Koa, Fastify, NestJS) with Jest, Vitest, or Mocha.
Ships in quality-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
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.
Check .agents/qa-context.md (fallback: .claude/qa-context.md) before answering. Pay attention to:
(req, res) app. The injection point differs (e.g., app, app.callback(), app.getHttpServer())..end((err, res) => ...) callbacks.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.
http.createServer.When not to use supertest:
fetch/axios + Jest, or pytest-api.axios.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.
| 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.
For tests that need cookies preserved across requests (login → fetch profile):
const agent = request.agent(app);
await agent
.post('/auth/login')
.send({ email: '[email protected]', password: 'Pa$$w0rd-fake' })
.expect(200);
const res = await agent.get('/me').expect(200);
expect(res.body.email).toBe('[email protected]');
request.agent(app) persists cookies across requests. Use it for session-cookie-based auth flows.
import app from '../src/app'; // the express() instance
const res = await request(app).get('/');
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.
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.
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.
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.
For tests that touch a database:
beforeEach opens a transaction, afterEach rolls back. Each test sees a clean DB.// 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 });
await / return — without one, the test ends before the promise settles, and assertion failures become unhandled rejections. ESLint no-floating-promises catches most.app.close() or your test runner hangs..end(cb) callbacks — they still work but mix poorly with async test runners; prefer await.toMatchObject or specific field checks..set('Content-Type', 'application/json') on raw .send(string) — if you send(JSON.stringify(...)) instead of send({...}), the content-type isn't auto-set.When helping with supertest, ask:
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
supertest, api-testing, http-testing, node-testing, integration-testing
npx claudepluginhub aks-builds/quality-skills --plugin quality-skills56 skills in this plugin
/accessibility-testingWhen the user wants to design, implement, or operate accessibility (a11y) testing — automated scans, manual audits, screen-reader testing, WCAG conformance, Section 508 / EAA compliance. Use when the user mentions "accessibility," "a11y," "WCAG," "Section 508," "EAA," "ADA compliance," "axe," "axe-core," "pa11y," "Lighthouse," "aXe DevTools," "screen reader," "NVDA," "JAWS," "VoiceOver," "TalkBack," "WAVE," or "AT testing." For visual diff see visual-regression. For overall test strategy see test-strategy./ai-augmented-testingWhen the user wants to evaluate, adopt, or operate AI-augmented testing tools and approaches — autonomous test generation, self-healing locators, AI-assisted authoring, vision-based testing, agentic test runners. Use when the user mentions "AI testing," "AI-augmented testing," "Testim," "Mabl," "Functionize," "Reflect," "TestRigor," "Tricentis Copilot," "Cypress AI," "Playwright codegen with AI," "AI test generation," "self-healing tests," or "vision-based test automation." For LLM-product evals see llm-eval-testing. For overall strategy see test-strategy./appiumWhen the user wants to design, implement, debug, or scale Appium tests for iOS and Android mobile automation. Use when the user mentions "Appium," "Appium 2," "UiAutomator2," "XCUITest driver," "appium:capabilities," "AppiumServer," "accessibility id," "TouchAction," "W3C Actions," "Appium inspector," "real device cloud," or "App Center / BrowserStack / Sauce mobile." For Android-native frameworks see espresso. For iOS-native see xcuitest. For React Native specifically see detox. For YAML-driven mobile flows see maestro. For desktop web automation see selenium / playwright / webdriverio.