Skip to content

Commit 80cae3f

Browse files
queengooborgtorifat
authored andcommitted
Add tests
1 parent d4b09f0 commit 80cae3f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/__tests__/utils.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Ajv from 'ajv';
2+
import betterAjvErrors from '../';
3+
import { getErrors } from '../utils.js';
4+
5+
describe('utils', () => {
6+
it('getErrors remaps ajv-errors custom messages', async () => {
7+
const node = {
8+
children: {},
9+
errors: [
10+
{
11+
keyword: 'errorMessage',
12+
dataPath: '/nested',
13+
schemaPath: '#/errorMessage',
14+
params: {
15+
errors: [
16+
{
17+
keyword: 'additionalProperties',
18+
dataPath: '/api/AbortController',
19+
schemaPath: '#/additionalProperties',
20+
params: { additionalProperty: 'AbortController$@*)$' },
21+
message: 'should NOT have additional properties',
22+
},
23+
],
24+
},
25+
message: 'Hello world!',
26+
},
27+
],
28+
};
29+
30+
const errors = getErrors(node);
31+
expect(errors).toStrictEqual([
32+
{
33+
keyword: 'additionalProperties',
34+
dataPath: '/api/AbortController',
35+
schemaPath: '#/additionalProperties',
36+
params: { additionalProperty: 'AbortController$@*)$' },
37+
message: 'Hello world!',
38+
},
39+
]);
40+
});
41+
});

0 commit comments

Comments
 (0)