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:
If an array node is provided with the first element's type not being Assert an error is thrown with the following message:
Should give at least one Assert on array nodes
This behaviour was already implemented but this message seems more adequate than the fallback message.
If any element's type of an array node is other than Object, Assert or Constraint an error is thrown with the following message:
Should give Assert or Constraint on array nodes
If there is more than one element with Object or Constraint type on an array node an error is thrown with the following message:
Should not give more than one constraint on array nodes
The fallback error message for providing invalid nodes has been improved/fixed to:
Should give an Assert, an Asserts array or Constraint
These changes do not break the current suite and tests were added for all cases, including a missing test for the fallback error message.
This PR improves validation of array nodes when instantiating or adding nodes to a
Constraint
object, since the following is currently allowed: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:
If an array node is provided with the first element's type not being
Assert
an error is thrown with the following message:Should give at least one Assert on array nodes
This behaviour was already implemented but this message seems more adequate than the fallback message.
If any element's type of an array node is other than
Object
,Assert
orConstraint
an error is thrown with the following message:Should give Assert or Constraint on array nodes
If there is more than one element with
Object
orConstraint
type on an array node an error is thrown with the following message:Should not give more than one constraint on array nodes
The fallback error message for providing invalid nodes has been improved/fixed to:
Should give an Assert, an Asserts array or Constraint
These changes do not break the current suite and tests were added for all cases, including a missing test for the fallback error message.