Skip to content

Commit

Permalink
Fix pref().when(). Closes #2128
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Sep 19, 2019
1 parent 1e7f3aa commit 96019a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ exports.preferences = function (target, source) {
Messages = Messages || require('./messages');

target = target || {};
source = source || {};

const merged = Object.assign({}, target, source);
if (source.errors &&
Expand Down
12 changes: 12 additions & 0 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3258,6 +3258,18 @@ describe('any', () => {
]);
});

it('works with prefs()', () => {

const schema = Joi.number()
.prefs({ errors: { label: 'key' } })
.when('$x', { then: Joi.number().min(1) });

Helper.validate(schema, { context: { x: true } }, [
[1, true],
[0, false, '"value" must be larger than or equal to 1']
]);
});

it('describes the base schema', () => {

const schema = Joi.number()
Expand Down

0 comments on commit 96019a7

Please sign in to comment.