Socket
Socket
Sign inDemoInstall

test-error

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    test-error

Function to check the type and message content of a Node.js Error


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
9.83 kB
Created
Weekly downloads
 

Readme

Source

test-error

NPM version Build Status Coverage Status

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 which error must be an instance. If not provided the parentage of error is not tested.
  • msgCheck {String|RegExp} Optional content expected in error.message. If a String is provided, the String must appear within error.message (at any position). If a RegExp is provided, its test method must accept error.message. If not provided the value of error.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

License

Keywords

FAQs

Last updated on 17 Mar 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc