From 563095a551bafedc150dfd61a2ec9bdf8f751167 Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Wed, 11 Sep 2019 01:51:18 -0700 Subject: [PATCH] Use helper --- test/types/alternatives.js | 5 +--- test/types/array.js | 48 ++++++++++++-------------------------- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/test/types/alternatives.js b/test/types/alternatives.js index 1425f9f5c..71111af97 100755 --- a/test/types/alternatives.js +++ b/test/types/alternatives.js @@ -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', () => { diff --git a/test/types/array.js b/test/types/array.js index 563dff568..3a232c260 100755 --- a/test/types/array.js +++ b/test/types/array.js @@ -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()', () => {