From f7f631d4cb648d6f7dbef5f03747b2d9eb9cf01f Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Mon, 1 Feb 2016 15:12:32 -0500 Subject: [PATCH] [changed] oneOf doesn't include empty values --- src/mixed.js | 2 +- test/mixed.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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])