1.0.2 • Published 8 years ago
test-error v1.0.2
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'));
});
}); // suiteInstallation
npm install test-errorUsage
testError(error, constructor, msgCheck)
error{Error} The error instance to be tested.constructor{Function} Optional class of whicherrormust be an instance. If not provided the parentage oferroris 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, itstestmethod must accepterror.message. If not provided the value oferror.messageis 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.jsonso coveralls updates are performed.
1.0.0 - 2018-03-13
- Initial release