Skip to content

Commit f7f631d

Browse files
committed
[changed] oneOf doesn't include empty values
1 parent c014a2a commit f7f631d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/mixed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ SchemaType.prototype = {
315315
name: 'oneOf',
316316
test(value) {
317317
let valids = this.schema._whitelist
318-
if (valids.length && !valids.has(value))
318+
if (valids.length && !(valids.has(value) || isAbsent(value)))
319319
return this.createError({ params: { values: valids.values().join(', ') }})
320320
return true
321321
}

test/mixed.js

+14
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ describe( 'Mixed Types ', function(){
7070
])
7171
})
7272

73+
it('should ignore absent values', function(){
74+
return Promise.all([
75+
mixed()
76+
.oneOf(['hello'])
77+
.isValid(undefined)
78+
.should.eventually.equal(true),
79+
string()
80+
.nullable()
81+
.oneOf(['hello'])
82+
.isValid(null)
83+
.should.eventually.equal(true)
84+
])
85+
})
86+
7387
it('should exclude values', function(){
7488
var inst = mixed().notOneOf(['hello', 5])
7589

0 commit comments

Comments
 (0)