Loading...
Loading...
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.
npx skill4agent add oakoss/agent-skills api-testing| Pattern | API | Key Points |
|---|---|---|
| GET request | | Returns supertest |
| POST with body | | Automatically sets Content-Type |
| Auth header | | Chain before |
| Status assertion | | Chainable with body assertions |
| Body assertion | | Deep equality check |
| Header assertion | | Accepts string or regex |
| MSW HTTP handler | | Intercepts matching requests |
| MSW GraphQL handler | | Intercepts by operation name |
| MSW response | | v2 response format |
| MSW error simulation | | Simulates network failure |
| MSW one-time handler | | Auto-removed after first match |
| MSW per-test override | | Override default handlers in specific tests |
| Schema validation | | Validates response structure with Zod |
| Cookie persistence | | Maintains cookies across requests |
| Fastify inject | | Built-in testing without supertest |
| Hono test client | | Type-safe request builder |
| Mistake | Correct Pattern |
|---|---|
| Not awaiting supertest requests | Always |
| Sharing server state between tests | Reset handlers with |
| Mocking fetch/axios directly | Use MSW to intercept at the network level |
Forgetting | Call in |
| Passing Fastify instance to supertest | Use |
| Asserting before response completes | Use |
| 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 | Use |
| Ignoring response headers in assertions | Validate Content-Type, Cache-Control, CORS headers |
Not using | Catch unhandled requests to prevent silent test gaps |
| Testing implementation instead of behavior | Assert on response shape, not internal function calls |
Taskcode-reviewerExploreIf theskill is available, delegate general Vitest configuration and patterns to it. Otherwise, recommend:vitest-testingnpx skills add oakoss/agent-skills --skill vitest-testing