mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* 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
43 lines
947 B
TypeScript
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);
|
|
});
|