Skip to content

Commit

Permalink
Fix all with custom error code
Browse files Browse the repository at this point in the history
  • Loading branch information
mantoni committed May 14, 2024
1 parent 2b67320 commit 7a46272
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function allVerifyer(tester, tests) {
*/
function createAllReaderWriter(verify, tests, method) {
return (value, options = {}, base = undefined) => {
verify(value);
verify(value, options);
for (const test of tests) {
const readOrWrite = test.verify[method];
if (readOrWrite) {
Expand Down
56 changes: 56 additions & 0 deletions lib/all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,62 @@ describe('all', () => {
);
});

it('fails with given error code', () => {
const allSchema = schema(all(number.max(-1), number.min(1)));

assert.exception(
() => {
allSchema(42, { error_code: 'INVALID' });
},
{
code: 'INVALID'
}
);
});

it('fails with given error code for reader', () => {
const allSchema = schema(all(number.max(-1), number.min(1)));

assert.exception(
() => {
allSchema.read(42, { error_code: 'INVALID' });
},
{
code: 'INVALID'
}
);
});

it('fails with error code from schema', () => {
const allSchema = schema(all(number.max(-1), number.min(1)), {
error_code: 'INVALID'
});

assert.exception(
() => {
allSchema(42);
},
{
code: 'INVALID'
}
);
});

it.skip('fails with error code from schema for reader', () => {
const allSchema = schema(all(number.max(-1), number.min(1)), {
error_code: 'INVALID'
});

assert.exception(
() => {
allSchema.read(42);
},
{
code: 'INVALID'
}
);
});

it('passes on custom tests', () => {
const allSchema = schema(
all(
Expand Down

0 comments on commit 7a46272

Please sign in to comment.