npm.io
4.2.0 • Published 4 years ago

it-throws

Licence
MIT
Version
4.2.0
Deps
0
Size
4 kB
Vulns
0
Weekly
0

it-throws

Build Status npm version Node.js Version

Wrapper around assert.throws and assert.rejects.

Installation

yarn add it-throws -D

Usage

import { itThrows, itRejects } from 'it-throws';

it('Throws', () => {
  itThrows(() => {
    throw new Error('foo');
  }, 'foo');
});

it('Rejects', async () => {
  await itRejects(Promise.reject(new Error('foo')), 'foo');
});

Is equivalent to:

import * as assert from 'assert';

it('Throws', () => {
  assert.throws(
    () => {
      throw new Error('foo');
    },
    {
      message: 'foo',
    },
  );
});

it('Rejects', async () => {
  await assert.rejects(Promise.reject(new Error('foo')), {
    message: 'foo',
  });
});