Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
[changed] oneOf doesn't include empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Feb 1, 2016
1 parent c014a2a commit f7f631d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions test/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down

0 comments on commit f7f631d

Please sign in to comment.