
api-testing
API testing patterns with supertest, MSW, and Vitest. Covers integration testing for REST APIs, HTTP request mocking with Mock Service Worker v2, response assertions, schema validation, test organization, and framework-specific patterns for Express, Fastify, and Hono. Use when writing integration tests for REST APIs, mocking HTTP requests, or testing API endpoints. Use for api-test, supertest, msw, mock-service-worker, integration-test, http-mock, endpoint-test, request-test.
- Installs
- 134
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/oakoss/agent-skills --skill api-testing- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads api-testing automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
API Testing
Overview
API testing validates HTTP endpoints by sending requests and asserting responses, covering status codes, headers, body content, and error handling. Supertest provides a fluent chainable API for integration testing against Express, Fastify, and Hono apps without starting a real server. MSW (Mock Service Worker) v2 intercepts outgoing HTTP requests at the network level, enabling realistic mocking of external services in both Node.js tests and browser environments.
When to use: Integration tests for REST APIs, testing middleware pipelines, validating request/response contracts, mocking third-party APIs in tests, testing error handling and edge cases.
When NOT to use: Unit testing pure functions (use direct assertions), E2E browser testing (use Playwright/Cypress), load/performance testing (use k6/Artillery), testing static file serving.
Quick Reference
| Pattern | API | Key Points |
|---|---|---|
| GET request | request(app).get('/path') | Returns supertest Test object |
| POST with body | request(app).post('/path').send(body) | Automatically sets Content-Type |
| Auth header | .set('Authorization', 'Bearer token') | Chain before .expect() |
| Status assertion | .expect(200) | Chainable with body assertions |
| Body assertion | .expect({ key: 'value' }) | Deep equality check |
| Header assertion | .expect('Content-Type', /json/) | Accepts string or regex |
| MSW HTTP handler | http.get('/api/users', resolver) | Intercepts matching requests |
| MSW GraphQL handler | graphql.query('GetUser', resolver) | Intercepts by operation name |
| MSW response | HttpResponse.json(data, { status }) | v2 response format |
| MSW error simulation | HttpResponse.error() | Simulates network failure |
| MSW one-time handler | http.get(path, resolver, { once: true }) | Auto-removed after first match |
| MSW per-test override | server.use(handler) | Override default handlers in specific tests |
| Schema validation | schema.parse(response.body) | Validates response structure with Zod |
| Cookie persistence | const agent = request.agent(app) | Maintains cookies across requests |
| Fastify inject | app.inject({ method, url }) | Built-in testing without supertest |
| Hono test client | testClient(app) | Type-safe request builder |
Common Mistakes
| Mistake | Correct Pattern |
|---|---|
| Not awaiting supertest requests | Always await request(app).get('/path') |
| Sharing server state between tests | Reset handlers with server.resetHandlers() in afterEach |
| Mocking fetch/axios directly | Use MSW to intercept at the network level |
Forgetting server.listen() in setup | Call in beforeAll, resetHandlers in afterEach |
| Passing Fastify instance to supertest | Use fastify.server (the underlying Node server) |
| Asserting before response completes | Use await or return the supertest chain |
| Hardcoding test data across many tests | Use factories or fixtures for test data |
| Not testing error responses | Test 4xx and 5xx paths alongside happy paths |
Using server.close() in afterEach | Use afterAll for close, afterEach for reset only |
| Ignoring response headers in assertions | Validate Content-Type, Cache-Control, CORS headers |
Not using onUnhandledRequest: 'error' | Catch unhandled requests to prevent silent test gaps |
| Testing implementation instead of behavior | Assert on response shape, not internal function calls |
Delegation
- Test structure review: Use
Taskagent - Code review: Delegate to
code-revieweragent - Pattern discovery: Use
Exploreagent
If the
vitest-testingskill is available, delegate general Vitest configuration and patterns to it. Otherwise, recommend:npx skills add oakoss/agent-skills --skill vitest-testing
References
- Supertest integration testing patterns for Express, Fastify, and Hono
- MSW request handlers, response resolvers, and server setup
- Test organization, fixtures, factories, and setup/teardown
- Response assertions, status codes, headers, and schema validation
FAQ
What does the api-testing skill do?
API testing patterns with supertest, MSW, and Vitest. Covers integration testing for REST APIs, HTTP request mocking with Mock Service Worker v2, response assertions, schema validation, test organization, and framework-specific patterns for Express, Fastify, and Hono. Use when writing integration tests for REST APIs, mocking HTTP requests, or testing API endpoints. Use for api-test, supertest, msw, mock-service-worker, integration-test, http-mock, endpoint-test, request-test.
How do I install api-testing?
Run npx skills add https://github.com/oakoss/agent-skills --skill api-testing in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/api-testing/ (personal) or .claude/skills/api-testing/ (project).
Which AI agents can use api-testing?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is api-testing safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains api-testing?
It is published by oakoss in oakoss/agent-skills. It has 134 recorded installs.
More from oakoss/agent-skills
ui-ux-polish
oakoss/agent-skills
Iterative UI/UX polishing workflow for web applications. Use when improving visual polish, refining desktop and mobile UX separately, running iterative enhancement cycles, applying design patterns like glassmorphism or bento grids, or auditing accessibility and WCAG compliance. Use for Stripe-level visual quality, responsive optimization, and design system alignment.
playwright
oakoss/agent-skills
Open the skill to read its SKILL.md instructions.
application-security
oakoss/agent-skills
Open the skill to read its SKILL.md instructions.
find-skills
oakoss/agent-skills
Open the skill to read its SKILL.md instructions.
drizzle-orm
oakoss/agent-skills
Open the skill to read its SKILL.md instructions.
Popular testing & qa skills
tdd
mattpocock/skills
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
grilling
mattpocock/skills
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
migrate-to-shoehorn
mattpocock/skills
Migrate test files from as type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace as in tests, or needs partial test data.
run-train
lllllllama/rigorpilot-skills
Rigor Train skill for deep learning research repositories. Use when a documented or selected training command should be run conservatively for startup verification, short-run verification, full kickoff, or resume, with command, config, seed, log, checkpoint, status, and metric evidence written to standardized trainoutputs/. Do not use for environment setup, exploratory sweeps, speculative idea implementation, or end-to-end orchestration.
test-driven-development
obra/superpowers
Use when implementing any feature or bugfix, before writing implementation code
finishing-a-development-branch
obra/superpowers
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work