DefinitelyTyped/types/jest-json-schema/jest-json-schema-tests.ts
Matt Scheurich 7823adabc9 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
2019-09-25 16:31:18 -07:00

43 lines
947 B
TypeScript

import { matchersWithOptions } from 'jest-json-schema';
expect.extend(
matchersWithOptions(
{
formats: {
test: /^test$/,
},
},
ajv => {
ajv.addKeyword('test', {
validate: (schema: any, data: string) => {
return schema && data === 'test';
},
metaSchema: {
type: 'boolean',
},
});
},
),
);
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', test: 'test' }).toMatchSchema(schema);
});