包详细信息

@bearz/assert

bearz-io223MIT0.1.0

Bearz assertion library primarily for testing.

assert, test, assertions

自述文件

@bearz/assert

Overview

The bearz/assert is now a remix of the std/assert library from Deno to enable modern asserts for Deno, Bun, and NodeJs; available as both npm and jsr packages.

The overall goal here is to make it easier to write javascript libaries that target multiple JavaScript runtimes.

logo

JSR npm version GitHub version

Documentation

Documentation is available on jsr.io

Usage

import { equal, ok, falsy } from "@bearz/assert";

// performs a deep equals
equal(1, 1);
ok(true);
fasly(false);

Classes

  • AssertionError the core assertion error.

Functions

  • arrayIncludes - asserts that an array includes values
  • assert - asserts that a value is truthy.
  • debug - logs a debug statement for tests. avoids polluting standard out unless debug is enabled.
  • setDebugTests - sets debugging for writing debug statements to true or false.
  • equal - asserts that values are deeply equal.
  • exists - asserts that a value exists.
  • fail - fails a test by throwing an AssertionError.
  • instanceOf - asserts that a value is an instance of a type.
  • nope - asserts that a value is falsy.
  • notOk - asserts that a value is falsy.
  • notEqual - asserts that two values are not deeply equal.
  • notInstanceOf - asserts that a value is not an instance of a type.
  • notStrictEqual - asserts that two values are not strictly equal (not the same ref).
  • ok - asserts that a value is truthy.
  • rejects - asserts that promise returns a rejection.
  • strictEqual - asserts that two values are strictly equal (same ref).
  • stringIncludes - asserts that a string includes a value.
  • throws - asserts that a function throws an exception.
  • truthy - asserts that a value is truthy.
  • unimplemented - asserts that a test is not yet implemented.

TODO

  • [x] Remove dependency on chai

Notes

This module is now a remix of the std/assert library from deno to enable modern asserts for Deno, Bun, and NodeJs; available as both npm and jsr packages.

The @bearz/testing and @bearz/assert modules can be used together to reduce the amount of shims and cruft when using denoland/dnt to publish jsr and npm modules.

The methods are renamed to enable importing all asserts as a single assert object. To demonstrate:

import * as assert from "@bearz/assert"

assert.ok()

If the @std lib deno packages or something similar were available as official npm and jsr packages, this package would not exist. It's only here to reduce the friction of writing cross runtime libraries.

License

MIT License

The majority of the code is now from std/assert which is under the MIT license. https://jsr.io/@std/assert/1.0.6/LICENSE