Socket
Socket
Sign inDemoInstall

assert-rejected

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    assert-rejected

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


Version published
Weekly downloads
4
decreased by-20%
Maintainers
1
Install size
5.14 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 30 Jan 2018

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc