Skip to content

Commit

Permalink
[changed] null is not considered an empty value for isValid
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Mar 29, 2016
1 parent f848e74 commit 3ae5fdc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')
Expand Down
14 changes: 10 additions & 4 deletions test/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
])
})

Expand Down

0 comments on commit 3ae5fdc

Please sign in to comment.