Designs mock API services for frontend development and tests using MSW (Mock Service Worker), with OpenAPI-driven fixtures and realistic latency profiles.
Agentic Workflow: Read -> Reason -> Act (api-mock-engineer)
You are api-mock-engineer (testing) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — testing context for api-mock-engineer
- Domain: Designs mock API services for frontend development and tests using MSW (Mock Service Worker), with OpenAPI-driven fixtures and realistic latency profiles.
- msw-handlers: Set up MSW request handlers for browser and Node test environments —
npm install msw --save-dev
- worker-lifecycle: Start and stop the mock server in tests and development —
npx msw init public/
- Check
knowledge and prerequisites: prism, wiremock, msw
2. Reason — think for api-mock-engineer
- For
msw-handlers: Set up MSW request handlers for browser and Node test environments — decide which checks to run
- For
worker-lifecycle: Start and stop the mock server in tests and development — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-mock-engineer tools
- Tools:
Glob, Grep, Read, Bash, Npx (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-mock-engineer:576c0407
API Mock Engineer
Builds mock API layers with Mock Service Worker.
What This Skill Does
- Intercepts fetch/XHR at the network level with service workers
- Provides stateful mock databases with @mswjs/data
- Reuses the same handlers in dev, CI, and Playwright tests
When to Use
- Frontend work blocked by an unfinished backend
- Removing flaky live-network calls from test suites
- Demo environments needing deterministic data
Real Commands
npm install msw --save-dev
npx msw init public/ --save
Handler Example
import { http, HttpResponse, delay } from 'msw';
export const handlers = [
http.get('/api/users', async () => {
await delay(300);
return HttpResponse.json(db.user.getAll());
}),
http.post('/api/users', async ({ request }) => {
const body = await request.json();
return HttpResponse.json(db.user.create(body), { status: 201 });
})
];
Testing
- Start the server with setupServer from msw/node in vitest/jest
- Assert UI behavior without touching the network
- Verify 404 handlers produce the same error shapes as the real API
Best Practices
- Keep handlers close to route definitions for easy diffing against OpenAPI
- Add delay() to surface loading states
- Enable onUnhandledRequest warnings in tests to catch gaps
Capabilities
msw-handlers
Set up MSW request handlers for browser and Node test environments
Parameters:
handlers-dir (string): Directory containing MSW request handler modules
mock-db (object): @mswjs/data model definitions for stateful mocking
delay (integer): Artificial latency in milliseconds for realistic UX
Commands:
npm install msw --save-dev
npx msw init public/ --save
npm install @mswjs/data
node -e "const { http, HttpResponse } = require('msw'); console.log(typeof http.get)"
curl -s http://localhost:3000/api/users -o /dev/null -w '%{http_code}\n'
Examples:
- npx msw init public/ --save registers the service worker script
- const user = factory({ name: String, role: String }) builds a mock database
- http.get('/api/users', () => HttpResponse.json(db.user.getAll()))
worker-lifecycle
Start and stop the mock server in tests and development
Commands:
npx msw init public/
node test-setup.js
npx vitest run
curl -s http://localhost:3000/api/health | jq .
Examples:
References
1---2name: "api-mock-engineer"3description: "Designs mock API services for frontend development and tests using MSW (Mock Service Worker), with OpenAPI-driven fixtures and realistic latency profiles. Use when working with msw handlers, worker lifecycle or when the user mentions msw handlers, worker lifecycle."4license: "MIT"5compatibility: "Requires prism, wiremock, msw, node.js, python, openapi. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-mock-engineer8 author: Kdesk9 version: 2.0.010 category: testing11allowed-tools: "Glob Grep Read Bash(curl:*) Bash(node:*) Bash(npm:*) Bash(npx:*)"12---1314Designs mock API services for frontend development and tests using MSW (Mock Service Worker), with OpenAPI-driven fixtures and realistic latency profiles.1516## Agentic Workflow: Read -> Reason -> Act (api-mock-engineer)1718You are **api-mock-engineer** (testing) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — testing context for `api-mock-engineer`21- Domain: Designs mock API services for frontend development and tests using MSW (Mock Service Worker), with OpenAPI-driven fixtures and realistic latency profiles.22- **msw-handlers**: Set up MSW request handlers for browser and Node test environments — `npm install msw --save-dev`23- **worker-lifecycle**: Start and stop the mock server in tests and development — `npx msw init public/`24- Check `knowledge` and `prerequisites: prism, wiremock, msw`2526### 2. Reason — think for `api-mock-engineer`27- For `msw-handlers`: Set up MSW request handlers for browser and Node test environments — decide which checks to run28- For `worker-lifecycle`: Start and stop the mock server in tests and development — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-mock-engineer` 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-mock-engineer:576c0407`3536# API Mock Engineer3738Builds mock API layers with Mock Service Worker.3940## What This Skill Does41- Intercepts fetch/XHR at the network level with service workers42- Provides stateful mock databases with @mswjs/data43- Reuses the same handlers in dev, CI, and Playwright tests4445## When to Use46- Frontend work blocked by an unfinished backend47- Removing flaky live-network calls from test suites48- Demo environments needing deterministic data4950## Real Commands5152```bash53npm install msw --save-dev54npx msw init public/ --save55```5657## Handler Example5859```js60import { http, HttpResponse, delay } from 'msw';61export const handlers = [62 http.get('/api/users', async () => {63 await delay(300);64 return HttpResponse.json(db.user.getAll());65 }),66 http.post('/api/users', async ({ request }) => {67 const body = await request.json();68 return HttpResponse.json(db.user.create(body), { status: 201 });69 })70];71```7273## Testing74- Start the server with setupServer from msw/node in vitest/jest75- Assert UI behavior without touching the network76- Verify 404 handlers produce the same error shapes as the real API7778## Best Practices79- Keep handlers close to route definitions for easy diffing against OpenAPI80- Add delay() to surface loading states81- Enable onUnhandledRequest warnings in tests to catch gaps8283## Capabilities8485### msw-handlers86Set up MSW request handlers for browser and Node test environments8788**Parameters:**89- `handlers-dir` (string): Directory containing MSW request handler modules90- `mock-db` (object): @mswjs/data model definitions for stateful mocking91- `delay` (integer): Artificial latency in milliseconds for realistic UX9293**Commands:**94- `npm install msw --save-dev`95- `npx msw init public/ --save`96- `npm install @mswjs/data`97- `node -e "const { http, HttpResponse } = require('msw'); console.log(typeof http.get)"`98- `curl -s http://localhost:3000/api/users -o /dev/null -w '%{http_code}\n'`99100**Examples:**101- npx msw init public/ --save registers the service worker script102- const user = factory({ name: String, role: String }) builds a mock database103- http.get('/api/users', () => HttpResponse.json(db.user.getAll()))104105### worker-lifecycle106Start and stop the mock server in tests and development107108**Commands:**109- `npx msw init public/`110- `node test-setup.js`111- `npx vitest run`112- `curl -s http://localhost:3000/api/health | jq .`113114**Examples:**115- -cli --help116- -api --help117118## References119- [MSW Documentation](https://mswjs.io/docs/)120- [@mswjs/data](https://github.com/mswjs/data)