test-error
v1.0.2
Published
Function to check the type and message content of a Node.js Error
Downloads
8
Readme
test-error
This module provides a simple function that can be used in
assert.throws
to verify that an error is an instance of a particular
class, and/or that its message has specific content.
Example
'use strict'
const assert = require('assert');
const testError = require('test-error');
// ...
describe('suite', function() {
it('should throw a TypeError', function() {
assert.throws(() => testMe(),
err => testError(err, TypeError, 'missing argument'));
});
}); // suite
Installation
npm install test-error
Usage
testError(error, [constructor], [msgCheck])
error
{Error} The error instance to be tested.constructor
{Function} Optional class of whicherror
must be an instance. If not provided the parentage oferror
is not tested.msgCheck
{String|RegExp} Optional content expected inerror.message
. If a String is provided, the String must appear withinerror.message
(at any position). If a RegExp is provided, itstest
method must accepterror.message
. If not provided the value oferror.message
is not tested.
Returns false
if a provided constructor
or msgCheck
verification
fails, true
otherwise.
Change Log
All changes since 1.0.0 relate to package documentation.
1.0.2 - 2018-03-17
- Correct documentation of behavior in the case where no verifications are provided.
1.0.1 - 2018-03-13
- Add script to
package.json
so coveralls updates are performed.
1.0.0 - 2018-03-13
- Initial release