Skip to content

Commit

Permalink
Merge pull request jquense#37 from itajaja/whitelist-required
Browse files Browse the repository at this point in the history
allow oneOf required validation
  • Loading branch information
jquense committed Mar 27, 2016
2 parents 1ca4dc6 + a5c680a commit 78f84c3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ json separate from validating it, via the `cast` method.
- [`ValidationError(String|Array<String> errors, Any value, String path)`](#validationerrorstringarraystring-errors-any-value-string-path)
- [mixed](#mixed)
- [`mixed.clone()`](#mixedclone)
- [`mixed.label(String label)`](#mixedlabel)
- [`mixed.label(String label)`](#mixedlabelstring-label)
- [`mixed.concat(Schema schema)`](#mixedconcatschema-schema)
- [`mixed.validate(Any value, [Object options, Function callback])`](#mixedvalidateany-value-object-options-function-callback)
- [`mixed.isValid(Any value, [Object options, Function callback]) -> Promise`](#mixedisvalidany-value-object-options-function-callback---promise)
Expand Down
2 changes: 0 additions & 2 deletions lib/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ SchemaType.prototype = {

if (typeof opts.message !== 'string' || typeof opts.test !== 'function') throw new TypeError('`message` and `test` are required parameters');

if (next._whitelist.length) throw new Error('Cannot add tests when specific valid values are specified');

var validate = createValidation(opts);

var isExclusive = opts.exclusive || opts.name && next._exclusive[opts.name] === true;
Expand Down
3 changes: 0 additions & 3 deletions src/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ SchemaType.prototype = {
if (typeof opts.message !== 'string' || typeof opts.test !== 'function')
throw new TypeError('`message` and `test` are required parameters')

if (next._whitelist.length)
throw new Error('Cannot add tests when specific valid values are specified')

var validate = createValidation(opts);

var isExclusive = (
Expand Down
10 changes: 9 additions & 1 deletion test/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ describe( 'Mixed Types ', function(){
.oneOf(['hello'])
.isValid(undefined)
.should.eventually.equal(true),
mixed()
.oneOf(['hello'])
.required()
.isValid(null)
.should.eventually.equal(false),
string()
.nullable()
.oneOf(['hello'])
Expand All @@ -96,7 +101,10 @@ describe( 'Mixed Types ', function(){
inst.validate(5).should.be.rejected.then(function(err){
err.errors[0].should.equal('this must not be one the following values: 5, hello')
}),
inst.oneOf([5]).isValid(5).should.eventually.equal(true)
inst.oneOf([5]).isValid(5).should.eventually.equal(true),

inst.isValid(null).should.eventually.equal(true),
inst.required().isValid(null).should.eventually.equal(false)
])
})

Expand Down

0 comments on commit 78f84c3

Please sign in to comment.