Registry / testing / jest-json-schema-extended

jest-json-schema-extended

JSON →
library1.0.1jsnpmunverified

Extension of jest-json-schema providing expressive, chainable matchers for JSON schema validation in Jest tests. Version 1.0.1, maintained as needed. Key differentiators: includes predefined types (uuid, dateTime, url, path, etc.), strict object checking, combined matchers like anyOf, exactly, arrayOfItems, and a simple expectToMatchSchema function. Handles common JSON validation needs with minimal boilerplate compared to raw ajv usage.

npm install jest-json-schema-extended
INSTALL
IMPORT
SIG · JEST-JSON-SCHEMA-E
J
jest-json-schema-extended
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.

setup
const { setup } = require('jest-json-schema-extended');
import { setup } from 'jest-json-schema-extended';
Package is CJS-only; ESM imports not supported. Must call setup() in test setup file.
expectToMatchSchema
const { expectToMatchSchema } = require('jest-json-schema-extended');
Not available as a Jest matcher extension; use function call directly.
strictObject
const { strictObject } = require('jest-json-schema-extended');
Options are optional; defaults to no additional properties.

Shows how to set up and use expectToMatchSchema with strictObject, arrayOfItems, stringType, and numberType matchers.

const { setup, expectToMatchSchema, stringType, numberType, arrayOfItems, anyOf, strictObject } = require('jest-json-schema-extended'); setup(); describe('JSON schema validation', () => { it('should match schema', () => { const data = { id: 'abc123', count: 42, items: [ { type: 'foo' }, { type: 'bar' } ] }; const schema = strictObject({ id: stringType, count: numberType, items: arrayOfItems( strictObject({ type: stringType }) ) }); expectToMatchSchema(data, schema); }); });
Debug
Known issues
breakingCalling setup() multiple times may register duplicates.
fix
Call setup() only once in a setup file to avoid duplicate matchers.
affects: >=1.0.0
deprecatedjest-json-schema is no longer actively maintained; affects underlying functionality.
fix
Consider migrating to ajv-based matchers or a more actively maintained library.
affects: >=1.0.0
gotchauuidType validates only structure (length, dashes) not UUID version; false positives possible.
fix
Use a dedicated UUID validator for strict version checking.
affects: >=1.0.0
gotchastrictObject by default rejects additional properties; may cause unexpected test failures if schema not fully specified.
fix
Explicitly pass { allowAdditionalProperties: true } if needed.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: expectToMatchSchema is not a function
setup() not called before using expectToMatchSchema in tests.
fix
Call setup() in a Jest setup file or at the top of the test file.
Jest: Cannot find module 'jest-json-schema-extended'
Package not installed or missing from package.json.
fix
Run 'npm install --save-dev jest-json-schema-extended'.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
jestrequiredCore testing framework; the package extends Jest's expect functionality.
jest-json-schemarequiredBase package that provides JSON schema matching; this package builds upon it.
Agent activity
13 hits · last 30 days
node
12
Resources
jest-json-schema-extended — npm install jest-json-schema-extended · libregistry