diff --git a/src/mixed.js b/src/mixed.js index 71f76f0..2346385 100644 --- a/src/mixed.js +++ b/src/mixed.js @@ -315,7 +315,7 @@ SchemaType.prototype = { name: 'oneOf', test(value) { let valids = this.schema._whitelist - if (valids.length && !valids.has(value)) + if (valids.length && !(valids.has(value) || isAbsent(value))) return this.createError({ params: { values: valids.values().join(', ') }}) return true } diff --git a/test/mixed.js b/test/mixed.js index 7f30668..bf16389 100644 --- a/test/mixed.js +++ b/test/mixed.js @@ -70,6 +70,20 @@ describe( 'Mixed Types ', function(){ ]) }) + it('should ignore absent values', function(){ + return Promise.all([ + mixed() + .oneOf(['hello']) + .isValid(undefined) + .should.eventually.equal(true), + string() + .nullable() + .oneOf(['hello']) + .isValid(null) + .should.eventually.equal(true) + ]) + }) + it('should exclude values', function(){ var inst = mixed().notOneOf(['hello', 5])