@ende/assert

ende add jsr:@ende/assert

Version 2026.10.15 on JSR.

A library of assertion functions. If the assertion is false an AssertionError will be thrown which will result in pretty-printed diff of the failing assertion.

This module is browser compatible, but do not rely on good formatting of values for AssertionError messages in browsers.

import { assert } from "@ende/assert";

assert("I am truthy"); // Doesn't throw
assert(false); // Throws `AssertionError`

Modules

Exports

  • AnyConstructor — Any constructor
  • ArrayLikeArg — An array-like object (`Array`, `Uint8Array`, `NodeList`, etc.) that is not a string
  • assert — Make an assertion, an error will be thrown if `expr` does not have a truthy value.
  • assertAlmostEquals — Make an assertion that `actual` and `expected` are almost equal numbers through a given tolerance. It can be used to take into account IEEE-754 double-precision floating-point representation limitations. If the values are not almost equal then throw.
  • assertArrayIncludes — Asserts that `actual` contains all values in `expected`, using deep equality for non-primitive values.
  • assertEquals — Make an assertion that `actual` and `expected` are equal, deeply. If not deeply equal, then throw.
  • assertExists — Make an assertion that actual is not null or undefined. If not then throw.
  • assertFalse — Make an assertion, an error will be thrown if `expr` has a truthy value.
  • assertGreater — Make an assertion that `actual` is greater than `expected`. If not then throw.
  • assertGreaterOrEqual — Make an assertion that `actual` is greater than or equal to `expected`. If not then throw.
  • assertInstanceOf — Make an assertion that `obj` is an instance of `type`. If not then throw.
  • AssertionError — Error thrown when an assertion fails.
  • assertIsError — Make an assertion that `error` is an `Error`. If not then an error will be thrown. An error class and a string that should be included in the error message can also be asserted.
  • assertLess — Make an assertion that `actual` is less than `expected`. If not then throw.
  • assertLessOrEqual — Make an assertion that `actual` is less than or equal to `expected`. If not then throw.
  • assertMatch — Make an assertion that `actual` match RegExp `expected`. If not then throw.
  • assertNotEquals — Make an assertion that `actual` and `expected` are not equal, deeply. If not then throw.
  • assertNotInstanceOf — Make an assertion that `obj` is not an instance of `type`. If so, then throw.
  • assertNotMatch — Make an assertion that `actual` not match RegExp `expected`. If match then throw.
  • assertNotStrictEquals — Make an assertion that `actual` and `expected` are not strictly equal, using Object.is for equality comparison. If the values are strictly equal then throw.
  • assertObjectMatch — Make an assertion that `expected` object is a subset of `actual` object, deeply. If not, then throw a diff of the objects, with mismatching properties highlighted.
  • assertRejects — Executes a function which returns a promise, expecting it to reject.
  • assertStrictEquals — Make an assertion that `actual` and `expected` are strictly equal, using Object.is for equality comparison. If not, then throw.
  • assertStringIncludes — Make an assertion that actual includes expected. If not then throw.
  • assertThrows — Executes a function, expecting it to throw. If it does not, then it throws.
  • equal — Deep equality comparison used in assertions.
  • fail — Forcefully throws a failed assertion.
  • Falsy — Assertion condition for assertFalse.
  • GetConstructorType — Gets constructor type
  • unimplemented — Use this to stub out methods that will throw when invoked.
  • unreachable — Use this to assert unreachable code.