Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg authored and torifat committed Apr 12, 2022
1 parent d4b09f0 commit 80cae3f
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/__tests__/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Ajv from 'ajv';
import betterAjvErrors from '../';
import { getErrors } from '../utils.js';

describe('utils', () => {
it('getErrors remaps ajv-errors custom messages', async () => {
const node = {
children: {},
errors: [
{
keyword: 'errorMessage',
dataPath: '/nested',
schemaPath: '#/errorMessage',
params: {
errors: [
{
keyword: 'additionalProperties',
dataPath: '/api/AbortController',
schemaPath: '#/additionalProperties',
params: { additionalProperty: 'AbortController$@*)$' },
message: 'should NOT have additional properties',
},
],
},
message: 'Hello world!',
},
],
};

const errors = getErrors(node);
expect(errors).toStrictEqual([
{
keyword: 'additionalProperties',
dataPath: '/api/AbortController',
schemaPath: '#/additionalProperties',
params: { additionalProperty: 'AbortController$@*)$' },
message: 'Hello world!',
},
]);
});
});

0 comments on commit 80cae3f

Please sign in to comment.