Skip to content
Back to skills

Mock Api

ASecurity

Stub or mock external services in tests so they run fast, offline, and deterministically

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 3, 2026
ai-agentsgotestingapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned September 3, 2026

npx -y skills add black141312/ada --skill mock-api --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Mock Api?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Mock Api
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/black141312-mock-api/badge)](https://www.skillsdirectory.com/skills/black141312-mock-api)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: mock-api
description: Stub or mock external services in tests so they run fast, offline, and deterministically
category: testing
---

# Mock API

Use when a test depends on an external service (HTTP API, third-party SDK) and you need it isolated and deterministic.

1. Identify the boundary to mock — the HTTP call or client method — and intercept at that seam, not deep inside your logic.
2. Choose the level: network-level interception (e.g. nock/MSW) for HTTP, or dependency injection/stubbing for client objects.
3. Define realistic responses for the cases under test: success payload, the error/4xx/5xx paths, and timeouts.
4. Wire the mock in setup and assert the request was made as expected (URL, method, body, headers) where it matters.
5. Reset or restore mocks between tests so stubs don't leak across cases.
6. Keep one real integration/contract test (or recorded fixture check) so the mock can't silently drift from the real API.

## Rules
- Mock at the network or client boundary, never by monkey-patching your own business logic.
- Base mock payloads on the real API's actual shape; an invented response that the real service never returns tests nothing.
- Always cover failure modes — non-2xx, malformed body, timeout — not just the happy response.
- Restore/reset all mocks in teardown so global state doesn't bleed between tests.
- Guard against drift with a contract or recorded-fixture test against the real service, run less often if needed.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.