api-testing

Write integration tests for REST APIs using supertest, MSW, and Vitest.

Updated Sep 5, 2026
One-click install
npx skills add https://github.com/pohlai88/afenda-xforge-v5 --skill api-testing-pohlai88
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-testing
Source: https://github.com/pohlai88/afenda-xforge-v5/tree/main/.agents/skills/api-testing
Command: npx skills add https://github.com/pohlai88/afenda-xforge-v5 --skill api-testing-pohlai88

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires supertest, msw, vitest, zod, and includes references (resource) components.

What problem does it solve? Writing reliable integration tests for HTTP APIs requires coordinating request builders, network mocking, and assertion patterns across different frameworks, which is error-prone and inconsistent without established conventions. ## Core Features & Use Cases - Supertest Integration Testing: Chainable request and assertion patterns for Express, Fastify, and Hono apps without starting a real server, including cookies, file uploads, and middleware testing. - MSW v2 Network Mocking: Intercept outgoing HTTP and GraphQL requests at the network level with handlers, per-test overrides, one-time handlers, delays, and error simulation. - Assertions and Test Organization: Response validation with Zod schemas, custom Vitest matchers, test data factories, fixtures, database isolation strategies, and setup/teardown patterns. - Use Case: When adding a new REST endpoint to an Express app, use this Skill to write a supertest integration test that asserts status codes and response shape, while mocking a third-party payment API with MSW handlers. ## Quick Start Write an integration test for my Express /api/users endpoint using supertest and mock the external auth service with MSW.

Frequently Asked Questions about api-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test REST API endpoints with supertest?

Pass your Express app instance directly to supertest without calling listen, then chain methods like get, post, send, set, and expect to build requests and assert responses. Always await the chain so assertions run after the response completes.

How to mock HTTP requests in Vitest with MSW?

Create handlers with the http or graphql namespaces from msw, start a server with setupServer in a setup file, and call server.listen in beforeAll with onUnhandledRequest set to error. Use server.use inside individual tests to override default handlers.

Can I use supertest with Fastify or Hono?

Fastify has a built-in inject method that is preferred over supertest; if you must use supertest, pass fastify.server rather than the Fastify instance. Hono provides app.request and a type-safe testClient from hono/testing instead.

Why do my MSW mocks leak between tests?

Mocks leak when server.resetHandlers is not called in afterEach, leaving per-test overrides active for subsequent tests. Call listen in beforeAll, resetHandlers in afterEach, and close in afterAll to isolate state.

When should I not use supertest or MSW for testing?

Avoid them for unit testing pure functions, which only need direct assertions, and for end-to-end browser testing, where Playwright or Cypress fit better. Load and performance testing requires dedicated tools like k6 or Artillery.