diff --git a/src/mixed.js b/src/mixed.js index 9cc540f..686e514 100644 --- a/src/mixed.js +++ b/src/mixed.js @@ -327,7 +327,7 @@ SchemaType.prototype = { name: 'oneOf', test(value) { let valids = this.schema._whitelist - if (valids.length && !(valids.has(value) || isAbsent(value))) + if (valids.length && !(value === undefined || valids.has(value))) return this.createError({ params: { values: valids.values().join(', ') diff --git a/test/mixed.js b/test/mixed.js index 4a43a0a..067ea6c 100644 --- a/test/mixed.js +++ b/test/mixed.js @@ -71,21 +71,27 @@ describe( 'Mixed Types ', function(){ }) it('should ignore absent values', function(){ - return Promise.all([ + return Promise.all([ mixed() .oneOf(['hello']) .isValid(undefined) .should.eventually.equal(true), mixed() + .nullable() .oneOf(['hello']) - .required() .isValid(null) .should.eventually.equal(false), - string() + mixed() + .oneOf(['hello']) + .required() + .isValid(undefined) + .should.eventually.equal(false), + mixed() .nullable() .oneOf(['hello']) + .required() .isValid(null) - .should.eventually.equal(true) + .should.eventually.equal(false) ]) })