assertion-error-diff
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

AssertionError Diff

Get It

npm install --save assertion-error-diff
# or 
yarn add assertion-error-diff

API

createAssertionError :: string -> a -> a -> AssertionError a

Creates an AssertionError

Example:

import { createAssertionError } from 'assertion-error-diff'
 
const error = createAssertionError('Not a truthy value', true, false)
 
throw error
errorToString :: Error -> string

Given an Error it will create a string representation. If the Error given
is an AssertionError it will create a diff of the expected and actual values.

Example:

import { errorToString, createAsssertionError } from 'assertion-error-diff'
 
errorToString(new Error('foo')) // 'Error: foo'
 
errorToString(createAssertionError('foo', 'bar', 'baz'))
// AssertionError: foo
// - expected + actual
//
// bar !== baz
isAssertionError :: Error -> boolean

Given an Error it returns true if that Error is an AssertionError
false otherwise.

Example:

import { isAssertionError, createAssertionError } from 'assertion-error-diff'
 
isAssertionError(new Error('foo')) // false
isAssertionError(createAssertionError('foo', 'bar', 'baz')) // true

Readme

Keywords

none

Package Sidebar

Install

npm i assertion-error-diff

Weekly Downloads

12

Version

1.0.0

License

MIT

Last publish

Collaborators

  • tylors