Skip to content

Commit 7a46272

Browse files
committed
Fix all with custom error code
1 parent 2b67320 commit 7a46272

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

lib/all.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function allVerifyer(tester, tests) {
8585
*/
8686
function createAllReaderWriter(verify, tests, method) {
8787
return (value, options = {}, base = undefined) => {
88-
verify(value);
88+
verify(value, options);
8989
for (const test of tests) {
9090
const readOrWrite = test.verify[method];
9191
if (readOrWrite) {

lib/all.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,62 @@ describe('all', () => {
168168
);
169169
});
170170

171+
it('fails with given error code', () => {
172+
const allSchema = schema(all(number.max(-1), number.min(1)));
173+
174+
assert.exception(
175+
() => {
176+
allSchema(42, { error_code: 'INVALID' });
177+
},
178+
{
179+
code: 'INVALID'
180+
}
181+
);
182+
});
183+
184+
it('fails with given error code for reader', () => {
185+
const allSchema = schema(all(number.max(-1), number.min(1)));
186+
187+
assert.exception(
188+
() => {
189+
allSchema.read(42, { error_code: 'INVALID' });
190+
},
191+
{
192+
code: 'INVALID'
193+
}
194+
);
195+
});
196+
197+
it('fails with error code from schema', () => {
198+
const allSchema = schema(all(number.max(-1), number.min(1)), {
199+
error_code: 'INVALID'
200+
});
201+
202+
assert.exception(
203+
() => {
204+
allSchema(42);
205+
},
206+
{
207+
code: 'INVALID'
208+
}
209+
);
210+
});
211+
212+
it.skip('fails with error code from schema for reader', () => {
213+
const allSchema = schema(all(number.max(-1), number.min(1)), {
214+
error_code: 'INVALID'
215+
});
216+
217+
assert.exception(
218+
() => {
219+
allSchema.read(42);
220+
},
221+
{
222+
code: 'INVALID'
223+
}
224+
);
225+
});
226+
171227
it('passes on custom tests', () => {
172228
const allSchema = schema(
173229
all(

0 commit comments

Comments
 (0)