Skip to content

Commit

Permalink
Use helper
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Sep 11, 2019
1 parent c07d0bf commit 563095a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 37 deletions.
5 changes: 1 addition & 4 deletions test/types/alternatives.js
Original file line number Diff line number Diff line change
Expand Up @@ -1536,10 +1536,7 @@ describe('alternatives', () => {

it('throws when missing alternatives', () => {

expect(() => {

Joi.alternatives().try();
}).to.throw('Missing alternative schemas');
expect(() => Joi.alternatives().try()).to.throw('Missing alternative schemas');
});

it('throws on unreachable condition', () => {
Expand Down
48 changes: 15 additions & 33 deletions test/types/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,22 @@ describe('array', () => {
expect(() => Joi.array('invalid argument.')).to.throw('The array type does not allow arguments');
});

it('errors on number', () => {

const err = Joi.array().validate(3).error;
expect(err).to.be.an.error('"value" must be an array');
expect(err.details).to.equal([{
message: '"value" must be an array',
path: [],
type: 'array.base',
context: { label: 'value', value: 3 }
}]);
});

it('converts a non-array string with number type', () => {

const err = Joi.array().validate('3').error;
expect(err).to.be.an.error('"value" must be an array');
expect(err.details).to.equal([{
message: '"value" must be an array',
path: [],
type: 'array.base',
context: { label: 'value', value: '3' }
}]);
});
it('errors on invalid type', () => {

it('errors on a non-array string', () => {

const err = Joi.array().validate('asdf').error;
expect(err).to.be.an.error('"value" must be an array');
expect(err.details).to.equal([{
message: '"value" must be an array',
path: [],
type: 'array.base',
context: { label: 'value', value: 'asdf' }
}]);
Helper.validate(Joi.array(), [
[3, false, {
message: '"value" must be an array',
path: [],
type: 'array.base',
context: { label: 'value', value: 3 }
}],
['3', false, {
message: '"value" must be an array',
path: [],
type: 'array.base',
context: { label: 'value', value: '3' }
}]
]);
});

describe('cast()', () => {
Expand Down

0 comments on commit 563095a

Please sign in to comment.