# pgte/nock

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/pgte-nock).**

13,108 stars · 757 forks · JavaScript · MIT

## Links

- GitHub: https://github.com/pgte/nock
- awesome-repositories: https://awesome-repositories.com/repository/pgte-nock.md

## Description

Nock is a Node.js HTTP mocking library used to intercept outgoing network requests and return predefined responses. It functions as a network request interceptor and HTTP mock server, allowing developers to simulate external API behavior for automated testing without making live network calls.

The project includes an API fixture recorder to capture real network interactions and save them as reusable data files for playback. It also features a network latency simulator that introduces artificial delays to outgoing HTTP responses to verify timeout handling and race conditions.

The library provides capabilities for integration test isolation by blocking unplanned outbound traffic and restricting requests to unmocked hosts. It supports network request validation to verify the parameters and headers sent to specific endpoints, and employs request matching filters to target dynamic hostnames, paths, and request bodies.

## Tags

### Testing & Quality Assurance

- [API Request Mocking](https://awesome-repositories.com/f/testing-quality-assurance/general-testing-utilities/test-utilities-assertions/network-api-mocking/api-request-mocking.md) — Provides tools to intercept network requests and simulate server responses to mimic external API behavior. ([source](https://github.com/pgte/nock#readme))
- [HTTP Mock Servers](https://awesome-repositories.com/f/testing-quality-assurance/http-mock-servers.md) — Functions as a simulated server environment that validates request expectations and returns mock data.
- [Network Fixture Recorders](https://awesome-repositories.com/f/testing-quality-assurance/network-fixture-recorders.md) — Captures real HTTP interactions from a live system to create reusable mock data for development and testing.
- [Network Interaction Recorders](https://awesome-repositories.com/f/testing-quality-assurance/network-interaction-recorders.md) — Captures real network interactions and saves them as reusable data files for playback during tests. ([source](https://github.com/pgte/nock#readme))
- [Response Simulators](https://awesome-repositories.com/f/testing-quality-assurance/network-resilience-simulators/response-simulators.md) — Simulates specific server behaviors, such as custom error codes or artificial network latency, to test application resilience.
- [HTTP Mocking](https://awesome-repositories.com/f/testing-quality-assurance/node-js-test-automation/http-mocking.md) — Intercepts network requests to return predefined responses and isolate application logic from external services.
- [Mock Expectation Verifiers](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/testing-frameworks/test-frameworks/assertions-and-validation/assertion-validation-utilities/expectation-presence-validation/mock-expectation-verifiers.md) — Validates that specific network requests occurred and asserts that all expected calls were completed. ([source](https://github.com/pgte/nock#readme))
- [Network Latency Simulators](https://awesome-repositories.com/f/testing-quality-assurance/api-network-testing/network-latency-simulators.md) — Introduces artificial delays to outgoing HTTP responses to verify timeout handling and race conditions.
- [Test Isolation](https://awesome-repositories.com/f/testing-quality-assurance/general-testing-utilities/test-isolation.md) — Prevents external dependencies from affecting test results by simulating API behavior and blocking unplanned outbound traffic.
- [Mock State Resetting](https://awesome-repositories.com/f/testing-quality-assurance/general-testing-utilities/test-utilities-assertions/test-data-management/test-mock-management-tools/mock-state-resetting.md) — Maintains a global map of active mocks and expectations that can be cleared or reset between test cycles.
- [Latency and Chunking Simulators](https://awesome-repositories.com/f/testing-quality-assurance/network-resilience-simulators/latency-and-chunking-simulators.md) — Introduces configurable millisecond delays to HTTP responses to verify timeout handling and race conditions. ([source](https://github.com/pgte/nock#readme))
- [Lifecycle Management](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/mocking-frameworks/lifecycle-management.md) — Provides controls to start, stop, or reset network interceptors to maintain a clean state between test scenarios. ([source](https://github.com/pgte/nock#readme))

### Data & Databases

- [Response Recordings](https://awesome-repositories.com/f/data-databases/api-response-caching/response-recordings.md) — Returns pre-recorded fixtures or predefined data packets to the application instead of making live network calls.

### Networking & Communication

- [Request Matching Engines](https://awesome-repositories.com/f/networking-communication/http-request-customization/custom-http-response-serving/http-response-stubbing/request-matching-engines.md) — Employs a matching engine to target dynamic hostnames, paths, and request bodies for selecting correct mock responses. ([source](https://github.com/pgte/nock#readme))
- [Network Request Interceptors](https://awesome-repositories.com/f/networking-communication/network-request-interceptors.md) — Captures and redirects outbound traffic to simulate external API behavior for automated testing.
- [Request-Response Interceptors](https://awesome-repositories.com/f/networking-communication/request-response-interceptors.md) — Redirects traffic from the native network stack to a virtual response handler based on the target hostname.
- [Request Validation](https://awesome-repositories.com/f/networking-communication/traffic-manipulation-scripts/request-validation.md) — Verifies that the application sends the correct parameters and headers to specific endpoints.

### Programming Languages & Runtimes

- [HTTP Mocking Libraries](https://awesome-repositories.com/f/programming-languages-runtimes/node-js-network-libraries/http-mocking-libraries.md) — Provides a Node.js library for intercepting outgoing HTTP requests and returning predefined responses.
- [Module Monkey Patching](https://awesome-repositories.com/f/programming-languages-runtimes/module-monkey-patching.md) — Overrides core Node.js HTTP and HTTPS modules to intercept outgoing requests before they reach the network.

### System Administration & Monitoring

- [API Response Recordings](https://awesome-repositories.com/f/system-administration-monitoring/execution-history-auditors/reverse-execution-simulation/record-and-replay-debugging/data-stream-recording-and-replay/api-response-recordings.md) — Provides a utility to record real network interactions and save them as reusable data files for playback.

### Security & Cryptography

- [Outbound Network Blockers](https://awesome-repositories.com/f/security-cryptography/network-infrastructure-security/web-network-security/network-security/network-routing-access-control/network-access-controls/outbound-network-blockers.md) — Blocks requests to unmocked hosts to prevent unexpected outbound network calls during test execution. ([source](https://github.com/pgte/nock#readme))

### Part of an Awesome List

- [Testing Frameworks](https://awesome-repositories.com/f/awesome-lists/devtools/testing-frameworks.md) — HTTP mocking and expectations.
