1.2 KiB
1.2 KiB
name, description, license, triggers
| name | description | license | triggers | |||
|---|---|---|---|---|---|---|
| service-interceptor | Creates API service wrappers that simulate network calls with artificial delays and error rates for robust UI testing (no backend required). | MIT |
|
Service Interceptor
When to use this skill
- Use when UI needs to consume an API-like interface while the backend is absent.
- Triggered by prompts to mock axios/fetch behavior or to add latency/failure simulation.
Instructions
-
First Step: Implement
src/services/api.tsexporting functions (getPapers,getPaperById,searchPapers) that return Promises and optionally usesetTimeoutto simulate delay. -
Second Step: Make the delay configurable; expose a
setMockDelay(ms)helper and an optionalerrorRateflag for testing error states. -
Third Step: Use mockData fixtures as response payloads and ensure the services return the same shape as a future real API.
Examples
await api.getPapers({ page: 1, pageSize: 10 }) // resolves after 300ms with { items, total }
Notes
- Document how to switch to a real API endpoint later by replacing the service implementation or toggling an environment variable.