Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

jest-schema-matcher

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-schema-matcher

[![npm version](https://badge.fury.io/js/jest-schema-matcher.svg)](https://badge.fury.io/js/jest-schema-matcher) ![Lint-Build-Test-Publish](https://github.com/ryparker/jest-schema-matcher/workflows/Lint-Build-Test-Publish/badge.svg) [![semantic-release](h


Version published
Weekly downloads
4
decreased by-87.1%
Maintainers
1
Weekly downloads
 
Created

Jest-Schema-Matcher

npm version Lint-Build-Test-Publish semantic-release XO code style

An opinionated Jest matcher that generates, validates, and versions JSON Schemas for your APIs.

:rocket: Quick start

  1. Add dependency
yarn add --dev jest-schema-matcher
  1. Set global variable SHOULD_UPDATE_SCHEMAS in your jest's global config
// jest.config.js

module.exports = {
  ...
  globals: {
    SHOULD_UPDATE_SCHEMAS: true, // If true, schemas will be written/updated
  }
}
  1. Add the matcher to your tests
test('Check against schema', () => {
  const object = {
    username: 'test_user_a124',
    password: 'fixtures_password',
  }

  expect(object).toMatchSchema('schemaName')
  /**
   * 1. If SHOULD_UPDATE_SCHEMAS === true:
   * Will create a new schema or update existing schema in same path as test file.
   * E.g. If test path is `.../__tests__/sample.tests.js`
   * Then schema will be created in `.../__tests__/schemas/schemaName.json`
   * --or--
   * If SHOULD_UPDATE_SCHEMAS === false:
   * Will infer a new schema and recommend schema changes if the saved schema could be improved.
   */

  /** 2. Will validate `object` against saved schema.*/
})

FAQs

Package last updated on 27 Aug 2020

Did you know?

Socket

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