From 3ae5fdc646b2f37ca6ff3e9eacad568e2faa83ee Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Tue, 29 Mar 2016 10:55:49 -0400 Subject: [PATCH] [changed] `null` is not considered an empty value for isValid --- src/mixed.js | 2 +- test/mixed.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/mixed.js b/src/mixed.js index 9cc540fc6..686e51464 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 4a43a0a3a..067ea6c4f 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) ]) })