Skip to content

Commit

Permalink
Additional test for #2077
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Aug 27, 2019
1 parent 15be5b7 commit f684b15
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3033,6 +3033,53 @@ describe('any', () => {
]);
});

it('validates multiple conditions (implicit valids)', () => {

const schema = Joi.object({
a: Joi.boolean(),
b: Joi.boolean(),
c: Joi.number()
.when('a', { is: true, then: 1 })
.when('b', { is: true, then: 2 })
});

Helper.validate(schema, [
[{ c: 0 }, true],
[{ c: 1 }, true],
[{ c: 2 }, true],
[{ a: true, c: 1 }, true],
[{ a: true, c: 2 }, false, null, {
message: '"c" must be one of [1]',
details: [{
message: '"c" must be one of [1]',
path: ['c'],
type: 'any.only',
context: { value: 2, label: 'c', key: 'c', valids: [1] }
}]
}],
[{ b: true, c: 2 }, true],
[{ b: true, c: 1 }, false, null, {
message: '"c" must be one of [2]',
details: [{
message: '"c" must be one of [2]',
path: ['c'],
type: 'any.only',
context: { value: 1, label: 'c', key: 'c', valids: [2] }
}]
}],
[{ a: true, b: true, c: 2 }, true],
[{ a: true, b: true, c: 1 }, false, null, {
message: '"c" must be one of [2]',
details: [{
message: '"c" must be one of [2]',
path: ['c'],
type: 'any.only',
context: { value: 1, label: 'c', key: 'c', valids: [2] }
}]
}]
]);
});

it('sets type whens', () => {

const schema = Joi.object({
Expand Down

0 comments on commit f684b15

Please sign in to comment.