A simple REST API mocking library for superagent in browser or Node.js. Version 0.5.2 (final release) with no updates since 2017. Allows defining route handlers for GET, POST, PUT, PATCH, DELETE with URL parameters and body access. Supports custom timeout, header matching, and route teardown. Differentiates by working directly on the superagent instance, no separate server needed, suitable for frontend testing.
npm install superagent-mockerNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic mock setup: import, attach to superagent, define a GET route with URL param, set timeout, and issue request.
Call mock.unmock() after each test to restore original behavior.
Consider alternatives like nock or msw for active support.
When asserting headers, use lowercase keys: req.headers['x-custom-header'].
Set mock.timeout to a number (e.g., 100) or a function returning a number.
Use: import mock from 'superagent-mocker';
Call mock(request) after both imports.
Ensure mock(request) is called before mock.get(...)