Narnia's Psychedelic Mushrooms
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

compare-errors

0.3.0 • Public • Published

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'
    // }

install

npm i compare-errors

Downloadsweekly downloads

0

version

0.3.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability