Tests Express APIs with supertest and jest: request assertions, route coverage, snapshot testing, and CI-friendly test configuration.
Agentic Workflow: Read -> Reason -> Act (api-test-supertest)
You are Api Test Supertest (testing) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — testing context for api-test-supertest
- Domain: Tests Express APIs with supertest and jest: request assertions, route coverage, snapshot testing, and CI-friendly test configuration.
- supertest: Test HTTP APIs in-process with supertest —
npm install -D supertest jest
- assertion-patterns: Assert status, body, and headers —
node -e "const request=require('supertest'); console.log(typeof request)"
- Check
knowledge and prerequisites: jest, pytest, postman
2. Reason — think for api-test-supertest
- For
supertest: Test HTTP APIs in-process with supertest — decide which checks to run
- For
assertion-patterns: Assert status, body, and headers — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-test-supertest tools
- Tools:
Glob, Grep, Read, Bash, Npx (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-test-supertest:ddcd3df7
API Test v3 - Supertest/Jest
In-process API testing.
What This Skill Does
- Tests routes without binding a port
- Asserts status, bodies, and headers
- Reports coverage per route
When to Use
- Node/Express API suites
- Fast unit-style endpoint tests
- Route regression coverage
Real Commands
npm install -D supertest jest
npx jest test/api.test.js --verbose
npx jest --coverage --collectCoverageFrom='routes/**/*.js'
Test Example
const request = require('supertest');
const app = require('../app');
test('creates a user', async () => {
const res = await request(app).post('/api/users').send({ name: 'alice' });
expect(res.status).toBe(201);
expect(res.body.id).toBeDefined();
});
Testing
- Cover success and error paths per route
- Use coverage thresholds in CI
- Keep tests independent with in-memory DBs
Best Practices
- Export the app separately from the server
- Test through the HTTP interface
- Group tests by route resource
Capabilities
supertest
Test HTTP APIs in-process with supertest
Parameters:
test-file (string): Test file path
coverage (boolean): Collect coverage
test-name (string): Filter by test name
Commands:
npm install -D supertest jest
npx jest test/api.test.js --verbose
npx jest --coverage --collectCoverageFrom='routes/**/*.js'
npx jest -t 'creates a user'
npm test
Examples:
- supertest(app).get('/api/users') mounts the app in-process
- jest --coverage reports route coverage
- -t filters to a single test name
assertion-patterns
Assert status, body, and headers
Commands:
node -e "const request=require('supertest'); console.log(typeof request)"
npx jest test/api.test.js --runInBand
npx jest --watch
Examples:
References
1---2name: "api-test-supertest"3description: "Tests Express APIs with supertest and jest: request assertions, route coverage, snapshot testing, and CI-friendly test configuration. Use when working with supertest, assertion patterns or when the user mentions supertest, assertion patterns."4license: "MIT"5compatibility: "Requires jest, pytest, postman, newman, supertest."6metadata:7 source: https://skillmd.com/skills/opknock/api-test-supertest8 author: Kdesk9 version: 2.0.010 category: testing11allowed-tools: "Glob Grep Read Bash(node:*) Bash(npm:*) Bash(npx:*)"12---1314Tests Express APIs with supertest and jest: request assertions, route coverage, snapshot testing, and CI-friendly test configuration.1516## Agentic Workflow: Read -> Reason -> Act (api-test-supertest)1718You are **Api Test Supertest** (testing) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — testing context for `api-test-supertest`21- Domain: Tests Express APIs with supertest and jest: request assertions, route coverage, snapshot testing, and CI-friendly test configuration.22- **supertest**: Test HTTP APIs in-process with supertest — `npm install -D supertest jest`23- **assertion-patterns**: Assert status, body, and headers — `node -e "const request=require('supertest'); console.log(typeof request)"`24- Check `knowledge` and `prerequisites: jest, pytest, postman`2526### 2. Reason — think for `api-test-supertest`27- For `supertest`: Test HTTP APIs in-process with supertest — decide which checks to run28- For `assertion-patterns`: Assert status, body, and headers — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-test-supertest` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Npx` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `api-test-supertest:ddcd3df7`3536# API Test v3 - Supertest/Jest3738In-process API testing.3940## What This Skill Does41- Tests routes without binding a port42- Asserts status, bodies, and headers43- Reports coverage per route4445## When to Use46- Node/Express API suites47- Fast unit-style endpoint tests48- Route regression coverage4950## Real Commands5152```bash53npm install -D supertest jest54npx jest test/api.test.js --verbose55npx jest --coverage --collectCoverageFrom='routes/**/*.js'56```5758## Test Example5960```js61const request = require('supertest');62const app = require('../app');6364test('creates a user', async () => {65 const res = await request(app).post('/api/users').send({ name: 'alice' });66 expect(res.status).toBe(201);67 expect(res.body.id).toBeDefined();68});69```7071## Testing72- Cover success and error paths per route73- Use coverage thresholds in CI74- Keep tests independent with in-memory DBs757677## Best Practices78- Export the app separately from the server79- Test through the HTTP interface80- Group tests by route resource8182## Capabilities8384### supertest85Test HTTP APIs in-process with supertest8687**Parameters:**88- `test-file` (string): Test file path89- `coverage` (boolean): Collect coverage90- `test-name` (string): Filter by test name9192**Commands:**93- `npm install -D supertest jest`94- `npx jest test/api.test.js --verbose`95- `npx jest --coverage --collectCoverageFrom='routes/**/*.js'`96- `npx jest -t 'creates a user'`97- `npm test`9899**Examples:**100- supertest(app).get('/api/users') mounts the app in-process101- jest --coverage reports route coverage102- -t filters to a single test name103104### assertion-patterns105Assert status, body, and headers106107**Commands:**108- `node -e "const request=require('supertest'); console.log(typeof request)"`109- `npx jest test/api.test.js --runInBand`110- `npx jest --watch`111112**Examples:**113- -cli --help114- -api --help115116## References117- [Supertest Docs](https://github.com/ladjs/supertest)118- [Jest Docs](https://jestjs.io/docs/getting-started)