Registry / testing / jest-snapshots-json-rest-api

jest-snapshots-json-rest-api

JSON →
library1.1.2jsnpmunverified

Jest snapshot serializer for JSON REST API responses. As of v1.1.2, this package allows you to snapshot HTTP response objects that match a `{ status, body }` structure, generating JSON Schema snapshots instead of raw JSON. This is useful for API testing with libraries like `supertest` or `light-my-request`. The serializer produces schema-based snapshots that are more resilient to data changes. The package is stable but has a narrow scope. It is maintained primarily via community updates, with no active major development.

npm install jest-snapshots-json-rest-api
INSTALL
IMPORT
SIG · JEST-SNAPSHOTS-JSO
J
jest-snapshots-json-rest-api
testingjavascriptv1.1.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
import serializer from 'jest-snapshots-json-rest-api'
const { default } = require('jest-snapshots-json-rest-api')
The package exports the serializer as a default export. In CommonJS, use `const serializer = require('jest-snapshots-json-rest-api')`.
serializer
expect.addSnapshotSerializer(require('jest-snapshots-json-rest-api'))
expect.addSnapshotSerializer(require('jest-snapshots-json-rest-api').default)
When using CommonJS, the default export is directly the serializer, not under a `.default` key.

Demonstrates using the serializer with supertest to generate JSON Schema snapshots for a REST endpoint.

const request = require('supertest'); const app = require('./app'); test('get a user', async () => { const response = await request(app).get('/users/'); expect(response).toMatchSnapshot(); });
Debug
Known issues
gotchaSnapshot output is a JSON Schema, not raw JSON. If you expect to match exact values, the schema may not capture dynamic data like dates or generated IDs.
fix
Ensure your tests check specific values separately from snapshot matching, or use classic Jest snapshots for exact matches.
affects: >=1.0.0
gotchaThe serializer only works if the object has `status` and `body` keys. Objects missing these fields will not be serialized and may cause test failures.
fix
Ensure your response object (e.g., supertest response) has the shape `{ status, body }`.
affects: >=1.0.0
deprecatedThis package is not actively maintained; there may be compatibility issues with newer versions of Jest.
fix
Consider using Jest's built-in snapshot functionality or custom serializers if updates are needed.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'jest-snapshots-json-rest-api' from 'test.js'
The package is not installed or not in the correct devDependencies.
fix
Run `yarn add --dev jest-snapshots-json-rest-api` or `npm install --save-dev jest-snapshots-json-rest-api`.
expect.addSnapshotSerializer is not a function
The serializer is not being passed correctly, or jest is not available.
fix
Make sure you call `expect.addSnapshotSerializer(serializer)` inside a test file or setup file. The serializer should be the default export from the package.
Snapshot did not match - Received serializes to the same string but is deeply different
The incoming object does not match the expected `{ status, body }` structure, or the schema has changed.
fix
Check that the response object has `status` and `body` properties. Alternatively, update the snapshot with `--updateSnapshot`.
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
jest-snapshots-json-rest-api — npm install jest-snapshots-json-rest-api · libregistry