Skip to content

mgenware/it-throws

Repository files navigation

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',
  });
});

About

Wrapper around assert.throws and assert.rejects

Resources

License

Stars

Watchers

Forks

Packages

No packages published