when rejected
Wait for a promise to be rejected, then delegate the reason to another assertion.
var rejectedPromise = expect.promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error('argh'));
});
});
return expect(rejectedPromise, 'when rejected', 'to equal', new Error('argh'));
It works with any assertion or expect.it
construct:
return expect(rejectedPromise, 'when rejected', expect.it('to have message', 'argh'));
If the response is fulfilled, the assertion fails with the following output:
var fulfilledPromise = expect.promise(function (resolve, reject) {
setTimeout(function () {
resolve(123);
});
});
return expect(fulfilledPromise, 'when rejected', 'to have message', 'argh');
expected Promise (fulfilled) => 123 when rejected to have message 'argh'
Promise (fulfilled) => 123 unexpectedly fulfilled with 123