Updated types for jest-json-schema@2.1 (#38465)

* updated jest-json-schema types with latest version of Ajv and support for extendAjv in matchersWithOptions

* updated jest-json-schema version in header

* removed patch version from header
This commit is contained in:
Matt Scheurich 2019-09-26 01:31:18 +02:00 committed by Ben Lichtman
parent 0881aed62f
commit 7823adabc9
3 changed files with 39 additions and 8 deletions

View File

@ -1,19 +1,21 @@
// Type definitions for jest-json-schema 1.2
// Type definitions for jest-json-schema 2.1
// Project: https://github.com/americanexpress/jest-json-schema#readme
// Definitions by: Igor Korolev <https://github.com/deadNightTiger>
// Matt Scheurich <https://github.com/lvl99>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
/// <reference types="jest" />
import * as ajv from "ajv";
import * as ajv from 'ajv';
declare global {
namespace jest {
interface Matchers<R> {
toBeValidSchema(): R;
toMatchSchema(schema: object): R;
}
}
}
export const matchers: jest.ExpectExtendMap;
export function matchersWithOptions(options: ajv.Options): jest.ExpectExtendMap;
export function matchersWithOptions(options: ajv.Options, extendAjv?: (ajv: ajv.Ajv) => void): jest.ExpectExtendMap;

View File

@ -1,13 +1,42 @@
import { matchers } from 'jest-json-schema';
import { matchersWithOptions } from 'jest-json-schema';
expect.extend(matchers);
expect.extend(
matchersWithOptions(
{
formats: {
test: /^test$/,
},
},
ajv => {
ajv.addKeyword('test', {
validate: (schema: any, data: string) => {
return schema && data === 'test';
},
metaSchema: {
type: 'boolean',
},
});
},
),
);
it('validates my json', () => {
it('validates schema', () => {
expect({
test: true,
format: 'test',
}).toBeValidSchema();
});
it('schema matches data', () => {
const schema = {
properties: {
hello: { type: 'string' },
test: {
test: true,
format: 'test',
},
},
required: ['hello'],
};
expect({ hello: 'world' }).toMatchSchema(schema);
expect({ hello: 'world', test: 'test' }).toMatchSchema(schema);
});

View File

@ -1,6 +1,6 @@
{
"private": true,
"dependencies": {
"ajv": "^4.11.5"
"ajv": "^6.10.2"
}
}