Registry / testing / superagent-mocker

superagent-mocker

JSON →
library0.5.2jsnpmunverified

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.

testing
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ESM import returns default function that takes superagent instance

import mock from 'superagent-mocker'

First argument is string URL pattern, not object

mock.get('/path', handler)

Method is named clearRoutes, not clear

mock.clearRoutes()

Shows basic mock setup: import, attach to superagent, define a GET route with URL param, set timeout, and issue request.

import request from 'superagent'; import mock from 'superagent-mocker'; mock(request); mock.get('/hello/:name', (req) => { return { message: `Hello ${req.params.name}!` }; }); mock.timeout = 50; request .get('/hello/World') .end((err, res) => { console.log(res.body); // { message: 'Hello World!' } });
Debug
Known footguns
gotchamock() modifies the superagent instance globally; all requests after calling mock(request) will be intercepted until mock.unmock() is called.
deprecatedThe package is unmaintained and may not work with modern superagent versions (>=4). Last release 0.5.2 was in 2017.
gotchaHeader keys are lowercased when returned in req.headers.
gotchaTimeout can be a function or number. If not set, requests may hang.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
3
ahrefsbot
1
Resources