Registry / testing / axios-vcr

axios-vcr

JSON →
library1.0.2jsnpmunverified

Axios-VCR is a set of middlewares for the Axios HTTP client that enables recording and replaying of HTTP requests for testing purposes. Current stable version is 1.0.2, released in 2017, with no active development. It writes request/response pairs to JSON cassette files, allowing deterministic and fast tests by avoiding real network calls. Unlike tools like nock or Polly.js, it integrates directly with Axios via middleware, but lacks cassette expiration, Mocha integration, and support for non-global Axios instances. Release cadence is stalled, making it suitable only for simple, legacy projects.

npm install axios-vcr
INSTALL
IMPORT
SIG · AXIOS-VCR
A
axios-vcr
testingjavascriptv1.0.2
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
const axiosVCR = require('axios-vcr')
Package uses CommonJS; no ESM export available. No named exports.
mountCassette
axiosVCR.mountCassette(path)
mountCassette(path) without axiosVCR context
Must be called on the axiosVCR instance; not importable directly
ejectCassette
axiosVCR.ejectCassette(path)
axiosVCR.ejectCassette() without path (required for cleanup)
Eject must match the mount path exactly

Records and replays a GET request using a JSON cassette file.

const axios = require('axios'); const axiosVCR = require('axios-vcr'); // Mount a cassette to record/replay requests axiosVCR.mountCassette('./test/fixtures/cats.json'); axios.get('https://api.example.com/cats') .then(response => { console.log('Response data:', response.data); // Eject when done (ensure this runs after all requests complete) axiosVCR.ejectCassette('./test/fixtures/cats.json'); }) .catch(err => { console.error(err); axiosVCR.ejectCassette('./test/fixtures/cats.json'); });
Debug
Known issues
breakingaxios-vcr does not support cassette expiration; recorded responses are reused indefinitely until cassette file is manually deleted.
fix
Delete or update the cassette file manually when you need fresh responses.
affects: <=1.0.2
breakingOnly works with global axios instance; requests made on custom axios instances (axios.create()) are not intercepted.
fix
Use the default axios instance or merge interceptors manually.
affects: <=1.0.2
deprecatedPackage is unmaintained since 2017; no fixes or updates for modern Axios versions.
fix
Consider alternatives like nock, Polly.js, or msw.
affects: >=1.0.2
gotchaCassette files must be valid JSON; malformed JSON will cause silent failures or errors.
fix
Ensure cassette files are created by the library initially, not manually.
affects: >=0.0.1
gotchaejectCassette must be called after all requests in a test complete; otherwise cassette may not be flushed leading to data loss.
fix
Use promise chaining or async/await to ensure eject runs after all requests.
affects: >=0.0.1
Errors
Common errors & fixes
Cannot find module 'axios-vcr'
Package not installed or not in node_modules
fix
Run 'npm install --save-dev axios-vcr'
axiosVCR.mountCassette is not a function
Incorrect import or package version mismatch
fix
Ensure you use 'const axiosVCR = require('axios-vcr')' (CommonJS)
TypeError: Cannot read property 'interceptors' of undefined
Axios is not installed or not a peer dependency
fix
Install axios: 'npm install axios'
ENOENT: no such file or directory, open './fixtures/test.json'
Cassette file path does not exist or directory missing
fix
Create the directory or use an absolute path
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
axiosrequiredPeer dependency; axios-vcr intercepts axios requests
lodashrequiredUsed internally for object manipulation; required at runtime
debugoptionalUsed for debug logging
Agent activity
23 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
axios-vcr — npm install axios-vcr · libregistry