diff --git a/src/mixed.js b/src/mixed.js index 71f76f007..2346385db 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 7f30668aa..bf163894d 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])