# assertion-error

> Error constructor for test and validation frameworks that implements standardized AssertionError specification.

Latest version **2.0.1** (published 2023-10-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install assertion-error
pnpm add assertion-error
yarn add assertion-error
bun add assertion-error
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2023-10-18 |
| First published | 2013-04-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Jake Luer |
| Maintainers | chaijs, keithamus |
| Keywords | test, assertion, assertion-error |

## Links

- npm: https://www.npmjs.com/package/assertion-error
- Repository: https://github.com/chaijs/assertion-error
- Homepage: https://github.com/chaijs/assertion-error#readme
- Issues: https://github.com/chaijs/assertion-error/issues
- npm.io page: https://npm.io/package/assertion-error

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2023-10-18
- 2.0.0 — 2021-10-05
- 1.1.0 — 2018-01-07
- 1.0.2 — 2016-06-06
- 1.0.1 — 2015-03-05
- 1.0.0 — 2013-06-08
- 0.1.0 — 2013-04-07

## README

<p align=center>
  AssertionError and AssertionResult classes.
</p>

<p align=center>
  <a href="https://github.com/chaijs/assertion-error/actions">
    <img
      alt="build:?"
      src="https://github.com/chaijs/assertion-error/actions/workflows/nodejs.yml/badge.svg"
    />
  </a><a href="https://www.npmjs.com/package/assertion-error">
    <img
      alt="downloads:?"
      src="https://img.shields.io/npm/dm/assertion-error.svg"
    />
  </a><a href="">
    <img
      alt="devDependencies:none"
      src="https://img.shields.io/badge/dependencies-none-brightgreen"
    />
  </a>
</p>

## What is AssertionError?

Assertion Error is a module that contains two classes: `AssertionError`, which
is an instance of an `Error`, and `AssertionResult` which is not an instance of
Error.

These can be useful for returning from a function - if the function "succeeds"
return an `AssertionResult` and if the function fails return (or throw) an
`AssertionError`.

Both `AssertionError` and `AssertionResult` implement the `Result` interface:

```typescript
interface Result {
  name: "AssertionError" | "AssertionResult";
  ok: boolean;
  toJSON(...args: unknown[]): Record<string, unknown>;
}
```

So if a function returns `AssertionResult | AssertionError` it is easy to check
_which_ one is returned by checking either `.name` or `.ok`, or check
`instanceof Error`.

## Installation

### Node.js

`assertion-error` is available on [npm](http://npmjs.org).

```
$ npm install --save assertion-error
```

### Deno

`assertion_error` is available on
[Deno.land](https://deno.land/x/assertion_error)

```typescript
import {
  AssertionError,
  AssertionResult,
} from "https://deno.land/x/assertion_error@2.0.0/mod.ts";
```

---
_Source: https://npm.io/package/assertion-error · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
