Registry / testing / axios-stubber

axios-stubber

JSON →
library1.0.7-alpha.1jsnpmunverified

A lightweight library for stubbing axios HTTP requests and responses in tests, providing a developer-friendly API to define stubs via inline objects, JSON files, or JS modules. The current version (1.0.7-alpha.1) supports global axios stubbing and recording real calls for later replay. Key differentiators: zero-config setup, support for both request/response stubbing and recording, and TypeScript type definitions included. It is less mature than alternatives like axios-mock-adapter, but offers a simpler stubbing API ideal for quick test setup. Development appears slow with alpha releases indicating experimental status.

npm install axios-stubber
INSTALL
IMPORT
SIG · AXIOS-STUBBER
A
axios-stubber
testingjavascriptv1.0.7-alpha.1
harness data pending
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.

default
import axiosStubber from 'axios-stubber';
const axiosStubber = require('axios-stubber');
The default export is for stubbing axios (ESM-only). CommonJS require will fail in Node < 11 or without ESM support.
axiosStubsRecorder
import { axiosStubsRecorder } from 'axios-stubber';
const axiosStubsRecorder = require('axios-stubber').axiosStubsRecorder;
Named export for recording stubs; must be destructured from the module. Avoid using default import for this.
types
import type { AxiosStubberResult } from 'axios-stubber';
TypeScript type imports are available from the package. Use `import type` for type-only imports to avoid runtime overhead.

Demonstrates basic usage: stubbing a GET request to return a predefined response, then verifying the mocked call.

import axios from 'axios'; import axiosStubber from 'axios-stubber'; test('axios-stubber example', async () => { const control = axiosStubber(axios, { request: { method: 'GET', url: 'https://w00t.com' }, response: { status: 201, body: { yes: 'It is' } } }); const { data, status } = await axios.get('https://w00t.com'); expect(data).toStrictEqual({ yes: 'It is' }); expect(status).toStrictEqual(201); control.restore(); });
Debug
Known issues
deprecatedVersion is 1.0.7-alpha.1: Semver major may have breaking changes before stable release.
fix
Pin to exact version and test thoroughly before upgrading.
affects: >=1.0.0-beta.0
gotchaaxiosStubber mutates the global axios instance; must call control.restore() after each test to avoid cross-test pollution.
fix
Always store the return value of axiosStubber and call restore() in afterEach/teardown.
affects: >=0.1.0
gotchaIf multiple stubs match the same request, the last registered stub wins; order matters.
fix
Define stubs in the order you expect them to match, or use a single stub per request pattern.
affects: >=0.1.0
breakingPackage is alpha; API may change without notice. Breaking changes could include function signature changes or removal of features.
fix
Lock to a specific version (e.g., 1.0.7-alpha.1) and review changelog before upgrading.
affects: >=1.0.0-alpha.0
Errors
Common errors & fixes
TypeError: axiosStubber is not a function
Using CommonJS require on an ESM-only default export.
fix
Use ES module import: `import axiosStubber from 'axios-stubber';`
Axios request not stubbed: [object Object]
Stub definition does not match the actual request. The library checks method, url, and optionally headers.
fix
Ensure the stub request object has the same method and url as the axios call. Use exact strings.
Cannot read properties of undefined (reading 'status')
Control.restore() called before the axios request, or missing stub for the request.
fix
Ensure stubs are registered before axios calls and restore after the test assertions.
Upgrade
Version history
1.0.7-alpha.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
axios-stubber — npm install axios-stubber · libregistry