compare-errors
v0.3.0
Published
Compare errors based on instance, constructor and message
Downloads
7
Readme
compare errors
Install
npm install compare-errors
Usage
You can compare errors based on:
constructor:
const err = new Error('foo') const res = compareErrors(Error)(err) // { // type: 'constructor', // matches: true, // actual: 'Error: foo', // expected: 'Error' // }
constructor and string message:
const err = new Error('foo') const res = compareErrors(Error, 'foo')(err) // { // type: 'message', // matches: true, // actual: 'foo', // expected: 'foo' // }
constructor and regex message:
const err = new Error('foo') const res = compareErrors(Error, /bar/)(err) // { // type: 'message', // matches: false, // actual: 'foo', // expected: /bar/ // }
just a string or regex:
const err = new Error('foo') const res = compareErrors(/foo/)(err) // { // type: 'message', // matches: true, // actual: 'foo', // expected: /foo/ // }
instance:
const err = new Error('foo') const err2 = new RangeError('foo') const res = compareErrors(err)(err2) // { // type: 'instance', // matches: false, // actual: 'RangeError: foo', // expected: 'Error: foo' // }