{"id":49462,"library":"superagent-mocker","title":"superagent-mocker","description":"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.","status":"abandoned","version":"0.5.2","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/shuvalov-anton/superagent-mocker","tags":["javascript","superagent","crud","mocks","stubs","rest","test"],"install":[{"cmd":"npm install superagent-mocker","lang":"bash","label":"npm"},{"cmd":"yarn add superagent-mocker","lang":"bash","label":"yarn"},{"cmd":"pnpm add superagent-mocker","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"patches superagent to intercept requests","package":"superagent","optional":false}],"imports":[{"note":"ESM import returns default function that takes superagent instance","wrong":"var mock = require('superagent-mocker')()","symbol":"mock","correct":"import mock from 'superagent-mocker'"},{"note":"First argument is string URL pattern, not object","wrong":"mock.get({url:'/path'}, handler)","symbol":"mock.get","correct":"mock.get('/path', handler)"},{"note":"Method is named clearRoutes, not clear","wrong":"mock.clear()","symbol":"mock.clearRoutes","correct":"mock.clearRoutes()"}],"quickstart":{"code":"import request from 'superagent';\nimport mock from 'superagent-mocker';\n\nmock(request);\n\nmock.get('/hello/:name', (req) => {\n  return { message: `Hello ${req.params.name}!` };\n});\n\nmock.timeout = 50;\n\nrequest\n  .get('/hello/World')\n  .end((err, res) => {\n    console.log(res.body); // { message: 'Hello World!' }\n  });","lang":"javascript","description":"Shows basic mock setup: import, attach to superagent, define a GET route with URL param, set timeout, and issue request."},"warnings":[{"fix":"Call mock.unmock() after each test to restore original behavior.","message":"mock() modifies the superagent instance globally; all requests after calling mock(request) will be intercepted until mock.unmock() is called.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Consider alternatives like nock or msw for active support.","message":"The package is unmaintained and may not work with modern superagent versions (>=4). Last release 0.5.2 was in 2017.","severity":"deprecated","affected_versions":">=0.0.1"},{"fix":"When asserting headers, use lowercase keys: req.headers['x-custom-header'].","message":"Header keys are lowercased when returned in req.headers.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Set mock.timeout to a number (e.g., 100) or a function returning a number.","message":"Timeout can be a function or number. If not set, requests may hang.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"search_vec":"'0.5.2':17 '2017':24 'access':40 'allow':25 'api':7 'bodi':39 'browser':13 'crud':67 'custom':42 'defin':26 'delet':34 'differenti':49 'direct':52 'final':18 'frontend':63 'get':30 'handler':28 'header':44 'instanc':56 'javascript':65 'librari':9 'match':45 'mock':8,68 'mocker':3 'need':60 'node.js':15 'paramet':37 'patch':33 'post':31 'put':32 'releas':19 'rest':6,70 'rout':27,47 'separ':58 'server':59 'simpl':5 'sinc':23 'stub':69 'suitabl':61 'superag':2,11,55,66 'superagent-mock':1 'support':41 'teardown':48 'test':64,71 'timeout':43 'updat':22 'url':36 'version':16 'work':51","created_at":"2026-06-07T17:01:53.865481+00:00","updated_at":"2026-06-07T17:01:53.865481+00:00","problems":[{"fix":"Use: import mock from 'superagent-mocker';","cause":"Importing as named export instead of default","error":"TypeError: mock is not a function"},{"fix":"Call mock(request) after both imports.","cause":"Forgot to call mock(request) before using mocked endpoints","error":"TypeError: request.get is not a function"},{"fix":"Ensure mock(request) is called before mock.get(...)","cause":"Trying to mock a route before calling mock(request)","error":"Cannot set property of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/shuvalov-anton/superagent-mocker","github":"ssh://git@github.com/shuvalov-anton/superagent-mocker","docs":null,"changelog":null,"pypi":null,"npm":"superagent-mocker","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}