Assert Rejects
Assert that a promise eventually rejects
Installation
npm install --save assert-rejects
Usage
const assertRejects =
API
assertRejects(promise[, error][, message])
Expects the promise
to reject. Returns a new promise that will resolve once the provided promise is resolved.
If specified, error
can be a constructor, RegExp, or validation function.
If specified, message
will be the message provided by the AssertionError
if the promise fails to reject.
Validate instanceof using constructor:
Validate error message using RegExp:
Custom error validation:
Note that error
can not be a string. If a string is provided as the second argument, then error
is assumed to be omitted and the string will be used for message
instead. This can lead to easy-to-miss mistakes:
// THIS IS A MISTAKE! DO NOT DO THIS! // Do this instead.