1.8.0 • Published 3 years ago

jest-schema-matcher v1.8.0

Weekly downloads
122
License
MIT
Repository
github
Last release
3 years ago

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.*/
})
1.8.0

3 years ago

1.7.13

3 years ago

1.7.14

3 years ago

1.7.11

3 years ago

1.7.12

3 years ago

1.7.10

3 years ago

1.7.9

4 years ago

1.7.8

4 years ago

1.7.7

4 years ago

1.7.6

4 years ago

1.7.5

4 years ago

1.7.4

4 years ago

1.7.3

4 years ago

1.7.2

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.0.2

4 years ago

1.2.0

4 years ago

1.3.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.0

4 years ago

0.0.2

4 years ago