diff --git a/README.md b/README.md index 3035f249a..ca828e557 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ json separate from validating it, via the `cast` method. - [`ValidationError(String|Array 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) diff --git a/lib/mixed.js b/lib/mixed.js index 20c068663..870049efb 100644 --- a/lib/mixed.js +++ b/lib/mixed.js @@ -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; diff --git a/src/mixed.js b/src/mixed.js index d994b9303..0085920bb 100644 --- a/src/mixed.js +++ b/src/mixed.js @@ -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 = ( diff --git a/test/mixed.js b/test/mixed.js index 660046d81..fd09001da 100644 --- a/test/mixed.js +++ b/test/mixed.js @@ -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']) @@ -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) ]) })