Registry / testing / jest-axios-snapshot

jest-axios-snapshot

JSON →
library1.0.1jsnpmunverified

A Jest snapshot serializer for Axios HTTP responses, enabling snapshot testing of HTTP response bodies and headers. Version 1.0.1 is the current stable release, with TypeScript types included. It serializes Axios response objects into a readable HTTP format, stripping the Date header by default but allowing custom transformers via setResponseTransformer. Differentiator: integrates seamlessly with Jest snapshot testing for Axios responses, supporting inline snapshots and custom header filtering. Built for use with axios-test-instance for testing Express/Koa apps.

npm install jest-axios-snapshot
INSTALL
IMPORT
SIG · JEST-AXIOS-SNAPSHO
J
jest-axios-snapshot
testingjavascriptv1.0.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.

setResponseTransformer
import { setResponseTransformer } from 'jest-axios-snapshot'
const { setResponseTransformer } = require('jest-axios-snapshot')
ESM-only; CJS require works in Node >=12 but not recommended for TypeScript.
jest-axios-snapshot (as serializer)
"snapshotSerializers": ["jest-axios-snapshot"]
import 'jest-axios-snapshot'
Not imported directly; add to Jest config as a snapshotSerializer.
default export or named
import jestAxiosSnapshot from 'jest-axios-snapshot'
No default export; use only as serializer or named import setResponseTransformer.

Shows how to configure Jest to use the serializer and snapshot test an Axios response.

// jest.config.js module.exports = { snapshotSerializers: ['jest-axios-snapshot'] }; // test file import axios from 'axios'; it('should fetch example.com', async () => { const response = await axios.get('https://example.com'); expect(response).toMatchSnapshot(); });
Debug
Known issues
gotchaThe Date header is stripped by default; to include it, you must use setResponseTransformer to preserve it.
fix
import { setResponseTransformer } from 'jest-axios-snapshot';
setResponseTransformer(response => response);
affects: >=1.0.0
gotchaThe serializer only works with Axios response objects; other objects passed to expect(...).toMatchSnapshot() will not be serialized.
fix
Ensure you pass the entire Axios response object, not just response.data.
affects: >=1.0.0
breakingv1.0.0 dropped support for Node <12; earlier versions (pre-1.0) may have supported older Node.
fix
Update Node.js to version 12 or higher.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'jest-axios-snapshot' from 'jest.config.js'
The package is not installed or Jest cannot resolve it due to module resolution configuration.
fix
Run npm install jest-axios-snapshot --save-dev and ensure it's listed in package.json.
Invalid serializer: expected a string or object
The snapshotSerializers entry might not be a string or the module exports incorrectly.
fix
Ensure the config has snapshotSerializers: ['jest-axios-snapshot'] (string).
TypeError: expect(...).toMatchInlineSnapshot is not a function
Using toMatchInlineSnapshot without configuring the serializer in Jest config.
fix
Add 'jest-axios-snapshot' to snapshotSerializers in Jest config.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
jest-axios-snapshot — npm install jest-axios-snapshot · libregistry