@kingjs/assert-throws

Throw an exception if a function fails to throw an exception.

Stats

StarsIssuesVersionUpdatedCreatedSize
@kingjs/assert-throws
1.0.63 years ago3 years agoMinified + gzip package size for @kingjs/assert-throws in KB

Readme

@kingjs/assert-throws

Throw an exception if a function fails to throw an exception.

Usage

Assert that a function throws an exception like this:

var assertThrows = require('@kingjs/assert-throws');
assertThrows(function() { });

throws:

"An assertion failed."

Provide a more descriptive error message like this:

var assertThrows = require('@kingjs/assert-throws');

assertThrows(
  function() { }, 
  "Expected an exception, but actually passed."
) 

throws:

"Expected an exception, but actually passed."

API

declare function assertThrows(func: Function, message?: string);

Parameters

func: Function expected to throw an exception.

message: Message to throw if func fails to throw an exception, else will throw "An assertion failed.".

Install

With npm installed, run

$ npm install @kingjs/assert-throws

License

MIT

Analytics

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.