vael:assert
Structural equality, identity, error, and rejection assertions.
Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes.
Exports a callable default assert function with assertion methods attached.
import ... from "vael:assert"
vaeljs-core; vael-assert (default) in vaeljs-lite-coreExample
Section titled “Example”import assert from "vael:assert";
assert.strictEquals(1 + 1, 2);assert.equals({ a: [1, 2] }, { a: [1, 2] });assert.throws(() => { throw new RangeError("bad index");}, RangeError);equalsv0.0.0-alpha.0actual and expected.notEqualsv0.0.0-alpha.0actual and expected are not structurally equal.strictEqualsv0.0.0-alpha.0Object.is(actual, expected).notStrictEqualsv0.0.0-alpha.0actual and expected differ under Object.is(actual, expected).failv0.0.0-alpha.0AssertionError (code = "VAEL_ASSERT").throwsv0.0.0-alpha.0callback throws an instance of expected, returning the thrown value.doesNotThrowv0.0.0-alpha.0callback returns without throwing, returning its result.rejectsv0.0.0-alpha.0callback rejects (or throws synchronously) with an instance of expected, resolving with the rejection reason.doesNotRejectv0.0.0-alpha.0callback returns a Promise or thenable that fulfills without throwing or rejecting, resolving with its fulfillment value.Functions
Section titled “Functions”equals
Section titled “equals”export function equals(actual: unknown, expected: unknown, message?: string): void;
Assert strict structural equality between actual and expected.
Prototypes must match; NaN equals NaN; -0 differs from 0; Map and
Set ignore iteration order; cycles are handled.
| Name | Type | Description |
|---|---|---|
actual | unknown | Observed value. |
expected | unknown | Expected value. |
message optional | string | Optional failure message. |
voidTypeError— whenmessageis not a string or arity is wrong.AssertionError— (code = "VAEL_ASSERT") when values differ.
import { equals } from "vael:assert";
equals(new Set([1, 2]), new Set([2, 1]));notEquals
Section titled “notEquals”export function notEquals(actual: unknown, expected: unknown, message?: string): void;
Assert that actual and expected are not structurally equal.
| Name | Type | Description |
|---|---|---|
actual | unknown | Observed value. |
expected | unknown | Value that actual must not structurally equal. |
message optional | string | Optional failure message. |
voidTypeError— whenmessageis not a string or arity is wrong.AssertionError— (code = "VAEL_ASSERT") when values are structurally equal.
strictEquals
Section titled “strictEquals”export function strictEquals(actual: unknown, expected: unknown, message?: string): void;
Assert identity equality under Object.is(actual, expected).
| Name | Type | Description |
|---|---|---|
actual | unknown | Observed value. |
expected | unknown | Expected value. |
message optional | string | Optional failure message. |
voidTypeError— whenmessageis not a string or arity is wrong.AssertionError— (code = "VAEL_ASSERT") whenObject.is(actual, expected)is false.
import { strictEquals } from "vael:assert";
strictEquals(Number.NaN, Number.NaN);notStrictEquals
Section titled “notStrictEquals”export function notStrictEquals(actual: unknown, expected: unknown, message?: string): void;
Assert that actual and expected differ under Object.is(actual, expected).
| Name | Type | Description |
|---|---|---|
actual | unknown | Observed value. |
expected | unknown | Value that actual must not match under Object.is. |
message optional | string | Optional failure message. |
voidTypeError— whenmessageis not a string or arity is wrong.AssertionError— (code = "VAEL_ASSERT") whenObject.is(actual, expected)is true.
export function fail(message?: string): never;
Unconditionally throw an AssertionError (code = "VAEL_ASSERT").
| Name | Type | Description |
|---|---|---|
message optional | string | Optional failure message. |
never — Never returns normally.TypeError— whenmessageis not a string or arity is wrong.AssertionError— always.
throws
Section titled “throws”export function throws<E>(
callback: () => unknown,
expected: abstract new (...args: any[]) => E,
message?: string,
): E;
export function throws(
callback: () => unknown,
expected?: RegExp | null,
message?: string,
): unknown;
Assert that synchronous callback throws an instance of expected,
returning the thrown value.
Returning a native Promise throws TypeError (use rejects instead).
Assert that synchronous callback throws (optionally matching expected
RegExp), returning the thrown value.
| Name | Type | Description |
|---|---|---|
callback | () => unknown | Synchronous function expected to throw. |
expected optional | (abstract new (...args: any[]) => E) | RegExp | null | Constructor function or class the thrown value must match via instanceof; Optional RegExp matched against the thrown value or error message. |
message optional | string | Optional failure message. |
E— The thrown error instance.unknown— The thrown value.
TypeError— on invalid arguments or Promise-returning callback.AssertionError— (code = "VAEL_ASSERT") whencallbackdoes not throw or mismatches.
import { throws } from "vael:assert";
const err = throws(() => JSON.parse("{"), SyntaxError);console.log(err.name);doesNotThrow
Section titled “doesNotThrow”export function doesNotThrow<T>(callback: () => T, message?: string): T;
Assert that synchronous callback returns without throwing, returning its
result.
Returning a native Promise throws TypeError (use doesNotReject instead).
| Name | Type | Description |
|---|---|---|
callback | () => T | Synchronous function expected not to throw. |
message optional | string | Optional failure message. |
T — The value returned by callback.TypeError— on invalid arguments or Promise-returning callback.AssertionError— (code = "VAEL_ASSERT") whencallbackthrows.
rejects
Section titled “rejects”export function rejects<E>(
callback: () => unknown,
expected: abstract new (...args: any[]) => E,
message?: string,
): Promise<E>;
export function rejects(
callback: () => unknown,
expected?: RegExp | null,
message?: string,
): Promise<unknown>;
Assert that callback rejects (or throws synchronously) with an instance of
expected, resolving with the rejection reason.
Assert that callback rejects (or throws synchronously), optionally
matching expected RegExp, resolving with the rejection reason.
| Name | Type | Description |
|---|---|---|
callback | () => unknown | Function returning a Promise/thenable expected to reject. |
expected optional | (abstract new (...args: any[]) => E) | RegExp | null | Constructor function or class the rejection reason must match via instanceof; Optional RegExp matched against the rejection reason. |
message optional | string | Optional failure message. |
TypeError— when arguments are invalid.AssertionError— (code = "VAEL_ASSERT") whencallbackfulfills, returns non-thenable, or mismatches.
import { rejects } from "vael:assert";
await rejects(async () => { throw new TypeError("bad input");}, TypeError);doesNotReject
Section titled “doesNotReject”export function doesNotReject<T>(callback: () => PromiseLike<T>, message?: string): Promise<T>;
Assert that callback returns a Promise or thenable that fulfills without
throwing or rejecting, resolving with its fulfillment value.
| Name | Type | Description |
|---|---|---|
callback | () => PromiseLike<T> | Function returning a Promise/thenable expected to fulfill. |
message optional | string | Optional failure message. |
Promise<T> — Promise resolving to the fulfillment value of callback.TypeError— when arguments are invalid.AssertionError— (code = "VAEL_ASSERT") whencallbackthrows, rejects, or returns non-thenable.
Classes
Section titled “Classes”AssertionError
Section titled “AssertionError”export class AssertionError extends Error {
override name: "AssertionError";
code: "VAEL_ASSERT";
operator: string;
actual?: unknown;
expected?: unknown;
constructor(message?: string, options?: AssertionErrorOptions);
}
Error thrown when a vael:assert assertion fails.
Carries code = "VAEL_ASSERT", name = "AssertionError", and operator.
constructor(message?: string, options?: AssertionErrorOptions);
Construct an AssertionError.
| Name | Type | Description |
|---|---|---|
message optional | string | Optional failure message. |
options optional | AssertionErrorOptions | Optional operator, actual, and expected metadata. |
| Property | Type | Description | Since |
|---|---|---|---|
name | "AssertionError" | Error name ("AssertionError"). | v0.0.0-alpha.0 |
code | "VAEL_ASSERT" | Machine-readable error code ("VAEL_ASSERT"). | v0.0.0-alpha.0 |
operator | string | Assertion operator name. | v0.0.0-alpha.0 |
actual optional | unknown | Observed value, if applicable. | v0.0.0-alpha.0 |
expected optional | unknown | Expected value or matcher, if applicable. | v0.0.0-alpha.0 |
Interfaces
Section titled “Interfaces”AssertionErrorOptions
Section titled “AssertionErrorOptions”export interface AssertionErrorOptions {
operator?: string;
actual?: unknown;
expected?: unknown;
}
Options accepted by new AssertionError(message, options).
| Property | Type | Description | Since |
|---|---|---|---|
operator optional | string | Assertion operator name (defaults to "assert"). | v0.0.0-alpha.0 |
actual optional | unknown | Observed value, if applicable. | v0.0.0-alpha.0 |
expected optional | unknown | Expected value or matcher, if applicable. | v0.0.0-alpha.0 |
VaelAssert
Section titled “VaelAssert”export interface VaelAssert {
(value: unknown, message?: string): asserts value;
readonly AssertionError: typeof AssertionError;
readonly ok: VaelAssert;
readonly equals: typeof equals;
readonly notEquals: typeof notEquals;
readonly strictEquals: typeof strictEquals;
readonly notStrictEquals: typeof notStrictEquals;
readonly fail: typeof fail;
readonly throws: typeof throws;
readonly doesNotThrow: typeof doesNotThrow;
readonly rejects: typeof rejects;
readonly doesNotReject: typeof doesNotReject;
}
Callable assert object exposing all assertion helpers as properties.
(value: unknown, message?: string): asserts value;
Assert that value is truthy.
| Name | Type | Description |
|---|---|---|
value | unknown | Value tested for truthiness. |
message optional | string | Optional failure message. |
asserts valueTypeError— whenmessageis not a string or arity is wrong.AssertionError— (code = "VAEL_ASSERT") whenvalueis falsy.
| Property | Type | Description | Since |
|---|---|---|---|
AssertionError readonly | typeof AssertionError | AssertionError constructor reference. | v0.0.0-alpha.0 |
ok readonly | VaelAssert | Alias for assert. | v0.0.0-alpha.0 |
equals readonly | typeof equals | Structural equality assertion helper. | v0.0.0-alpha.0 |
notEquals readonly | typeof notEquals | Structural inequality assertion helper. | v0.0.0-alpha.0 |
strictEquals readonly | typeof strictEquals | Object.is identity equality assertion helper. | v0.0.0-alpha.0 |
notStrictEquals readonly | typeof notStrictEquals | Object.is identity inequality assertion helper. | v0.0.0-alpha.0 |
fail readonly | typeof fail | Unconditional failure helper. | v0.0.0-alpha.0 |
throws readonly | typeof throws | Synchronous throw assertion helper. | v0.0.0-alpha.0 |
doesNotThrow readonly | typeof doesNotThrow | Synchronous non-throw assertion helper. | v0.0.0-alpha.0 |
rejects readonly | typeof rejects | Asynchronous rejection assertion helper. | v0.0.0-alpha.0 |
doesNotReject readonly | typeof doesNotReject | Asynchronous fulfillment assertion helper. | v0.0.0-alpha.0 |
Constants
Section titled “Constants”assert
Section titled “assert”export const assert: VaelAssert;
Assert that value is truthy.
TypeError— whenmessageis not a string or arity is wrong.AssertionError— (code = "VAEL_ASSERT") whenvalueis falsy.
import { assert } from "vael:assert";
assert(2 > 1, "math should hold");export const ok: VaelAssert;
Alias for assert (identical function object).
Default Export
Section titled “Default Export”default export
Section titled “default export”export default assert;
Default export: the callable assert function with all assertion properties.
