http-mocking

Mock HTTP interactions in unit tests using the nock library.

6|Updated Feb 20, 2025
One-click install
npx skills add https://github.com/zerobias-org/module --skill http-mocking
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: http-mocking
Source: https://github.com/zerobias-org/module/tree/main/.claude/skills/http-mocking
Command: npx skills add https://github.com/zerobias-org/module --skill http-mocking

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Keeps tests deterministic by mocking HTTP requests with nock, avoiding flaky network calls.

Core Features & Use Cases

  • Strict HTTP-level mocking: Mock requests at the network layer using nock, avoiding internal method stubs.
  • Accurate request matching: Validate method, path, headers, and query parameters to reflect real API interactions.
  • Reliable cleanup and verification: Use afterEach to clean mocks and verify with isDone().
  • Use Case: Write unit tests that intercept external API calls and assert the expected payloads are returned without real network access.

Quick Start

Run a unit test that uses nock to intercept an HTTP GET to https://api.example.com/users and verify the mock is consumed.

Frequently Asked Questions about http-mocking

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

FAQPage Schema
How do I stop flaky unit tests caused by external API calls?

Stop flaky unit tests by mocking HTTP interactions with nock, which intercepts external API requests at the network layer to provide deterministic responses without real network access.

How does nock match HTTP requests during unit testing?

Nock matches HTTP requests by enforcing strict request-level validation across method, path, headers, and query parameters to ensure mocked interactions accurately reflect real API behaviors.

What is the best way to clean up HTTP mocks between test cases?

The best way to clean up HTTP mocks is using an afterEach hook to remove interceptors and calling nock's isDone() method to verify that all expected mocked requests were consumed.

Can I use other HTTP mocking libraries alongside nock for network interception?

No, you must use nock exclusively as the allowed library for HTTP mocking, ensuring all network-level interceptors and request stubs are managed through a single, consistent framework.

Why should I mock HTTP interactions at the network layer instead of stubbing internal methods?

Mock HTTP interactions at the network layer to avoid stubbing internal methods, ensuring your unit tests validate the actual request payloads, headers, and routing logic that your application generates.