Socket
Socket
Sign inDemoInstall

assertion-error

Package Overview
Dependencies
0
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

assertion-error

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


Version published
Maintainers
2
Weekly downloads
9,752,208
increased by0.55%
Install size
6.55 kB

Weekly downloads

Package description

What is assertion-error?

The assertion-error package is used to create error objects that are specifically meant for testing assertions. It is commonly used in conjunction with assertion libraries to provide a more descriptive error message when an assertion fails. The error object created by assertion-error includes a message and can also include properties that describe the assertion that failed.

What are assertion-error's main functionalities?

Creating an AssertionError instance

This feature allows you to create an instance of an AssertionError with a custom message. This is useful when you want to throw a specific error in your tests when an assertion fails.

{"const AssertionError = require('assertion-error');
const error = new AssertionError('expected value to be true');
throw error;"}

Other packages similar to assertion-error

Readme

Source

AssertionError and AssertionResult classes.

build:? downloads:? devDependencies:none

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:

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.

$ npm install --save assertion-error

Deno

assertion_error is available on Deno.land

import {AssertionError, AssertionResult} from 'https://deno.land/x/assertion_error@2.0.0/mod.ts'

Keywords

FAQs

Last updated on 05 Oct 2021

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