guillaumepotier / validator.js

Powerful objects and strings validation in javascript for Node and the browser
http://validatorjs.org
MIT License
255 stars 39 forks source link

Add validation adding array nodes to Constraint #62

Open ricardogama opened 7 years ago

ricardogama commented 7 years ago

This PR improves validation of array nodes when instantiating or adding nodes to a Constraint object, since the following is currently allowed:

var constraint = new Constraint({
  foo: [new Assert().Required, 'foobar']
});

Although an error is thrown when validating against the constraint, the error could be previously thrown when instantiating it and with a more adequate message.

With such motivation these changes lead to the following behaviour:

These changes do not break the current suite and tests were added for all cases, including a missing test for the fallback error message.