Version 4.0.1. A lightweight HTTP mocking library for Node.js that intercepts HTTP traffic during tests. It automatically restores the http module after each test (via a registered afterEach block) and fails if any mocks were not exercised. Supports both simple inline mocking and a callback-based approach for scoping. Differentiates from alternatives like nock by its automatic cleanup and integration with test frameworks.
npm install httpceptionVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic HTTP mocking with automatic cleanup via afterEach block.
Use the callback form to scope mocks explicitly: httpception({...}, () => { ... })Upgrade Node to >=6.0.0 or stay on v2.x.
Use a function as request to ignore certain parts: request: { url: '/foo', method: 'GET', query: { bar: 'baz' } }Ensure the callback returns the promise or handle errors properly.
Check the request URL and method; ensure the mock definition is correct.
Ensure all mocks are exercised during the test, or use callback form.
Use require('httpception') or default import.