to be rejected

  • <Promise> to be rejected

Asserts that a promise is rejected.

const promiseThatWillBeRejected = new Promise(function (resolve, reject) {
  setTimeout(reject, 1);
});
 
return expect(promiseThatWillBeRejected, 'to be rejected');

If the promise is fulfilled, the assertion will fail with the following output:

const fulfilledPromise = new Promise(function (resolve, reject) {
  setTimeout(resolve, 1);
});
 
return expect(fulfilledPromise, 'to be rejected');
expected Promise to be rejected
  
Promise unexpectedly fulfilled