Skip to content

Testing helper function allowing deeper inspection of errors than should.throw

License

Notifications You must be signed in to change notification settings

bodylabs/should-throw-instanceof

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

should-throw-instanceof

Testing helper function allows deeper inspection of errors than should.throw.

Usage

Give it callable code block, the type of error you expect, and any number of additional string, regex, and function 'matchers'. Example with both a string and a function matcher:

var shouldThrowInstanceof = require('should-throw-instanceof');

it('calling undefined() throws TypeError with stack', function () {
    shouldThrowInstanceof(
        function () { undefined(); },
        TypeError,
        'undefined is not a function',
        function (err) { return 'stack' in err; }
    );
});

String and regex matchers will be applied to the error message field (strings are checked for equality). Functions will be applied to the whole error object (checked for truthy return value and no exception thrown).

Any other type of matcher argument is not explicitly supported, but will be passed directly to should.match and checked over the whole error object.

Installation

npm install should-throw-instanceof

Contribute

  • Issue Tracker: github.com/bodylabs/should-throw-instanceof/issues
  • Source Code: github.com/bodylabs/should-throw-instanceof

Pull requests welcome!

Support

If you are having issues, please let us know.

License

The project is licensed under the two-clause BSD license.

About

Testing helper function allowing deeper inspection of errors than should.throw

Resources

License

Stars

Watchers

Forks

Packages

No packages published