🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

assert-rejected

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert-rejected

Assert that a promise has been rejected, optionally with a message

1.1.1
latest
Version published
Weekly downloads
4
-20%
Maintainers
1
Weekly downloads
 
Created

assert-rejected

Assert that a promise has been rejected, optionally with a message

Test APIs that are expected to return rejected promises given certain errors.

npm install --save-dev assert-rejected

Example

var assertRejected = require("assert-rejected");

var rejected = Promise.reject(new Error("Whoops!"));

assertRejected(rejected).then(function(){
    console.log("Yup! It rejected!")
});

var resolved = Promise.resolve("All Good!");

assertRejected(resolved).catch(function(){
    console.log("Oh no, it wasn't rejected!");
});

var rejectedWithMessage = Promise.reject(new Error("Whoopsies"));

assertRejected(rejectedWithMessage, "Whoopsies").then(function () {
    console.log("Rejected with the expected message!");
});

API

assertRejected(promise, message)

Checks whether a given promise has been rejected

  • promise : The promise to check
  • message : Optionally specify what error the message should contain

Returns a promise which resolves if everything is OK

Includes typescript typings.

FAQs

Package last updated on 30 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts