mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
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:
parent
0881aed62f
commit
7823adabc9
8
types/jest-json-schema/index.d.ts
vendored
8
types/jest-json-schema/index.d.ts
vendored
@ -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;
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"ajv": "^4.11.5"
|
||||
"ajv": "^6.10.2"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user