Declarative data validations.
By @michasherman
What if your promise can reject with different messages? No problem! You can reject the promise with your own message by passing it to the rejection callback.
Notice that when using rejection messages we do not need to pass statement
argument to test
. This means that the statement will always be inferred
from the rejection message.
In case you do pass statement
, it will serve as a fallback message in any
case that the rejection message is not provided.
test('name', new Promise((resolve, reject) => {
fetch(`/checkUsername?name=${name}`)
.then(res => res.json)
.then(data => {
if (data.status === 'fail') {
reject(data.message); // rejects with message and marks the test as failing
} else {
resolve(); // completes. doesn't mark the test as failing
}
});
}));
validationErrors
and validationWarnings
output properties to errors
and warnings
..done()
callbacks only run once..after()
callback that can run after a specific field finished execution.lessThan
, greaterThan
, lessThanOrEquals
, greaterThanOrEquals
, numberEquals
, numberNotEquals
).longerThan
, shorterThan
, longerThanOrEquals
, shorterThanOrEquals
, lengthEquals
, lengthNotEquals
).equals
, notEquals
).hasValidationErrors
, hasValidationWarnings
.anyOf
, allOf
, noneOf
).smallerThan
, largerThan
, smallerThanOrEquals
, largerThanOrEquals
, sizeEquals
, sizeNotEquals
).Fixed documentation site