Socket
Socket
Sign inDemoInstall

jest-json-schema-matchers

Package Overview
Dependencies
7
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest-json-schema-matchers

Matchers for validating json schema against json data (with working $refs)


Version published
Weekly downloads
264
increased by111.2%
Maintainers
1
Install size
4.05 MB
Created
Weekly downloads
 

Readme

Source

jest-json-schema-matchers

Install

npm install jest-json-schema-matchers

Example usage

// __tests__/data/data.json

{
  "base": {
    "referenced": {
      "name": "Referenced data schema"
    }
  }
}


// __tests__/schemas/base.json

{
  "type": "object",
  "required": ["base"],

  "properties": {
    "base": {
      "type": "object",
      "required": ["referenced"],

      "properties": {
        "referenced": {
          "$ref": "descriptions/referenced.json"
        }
      }
    }
  }
}

// __tests__/schemas/descriptions/referenced.json

{
  "type": "object",
  "required": ["name"],

  "properties": {
    "name": {
      "type": "string"
    }
  }
}

// __tests__/index.spec.js

const matchers = require('jest-json-schema-matchers');
expect.extend(matchers({
  schemaRoot: '__tests__/schemas/',
}));

describe('jest-json-schema-matchers', () => {
  it('matches json schema and resolves references', () => {
    const data = require('./data/data.json');

    expect(data).toMatchSchema('base.json');
  });
})

FAQs

Last updated on 13 Jul 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc