@ende/expect
ende add jsr:@ende/expectVersion 2026.10.15 on JSR.
This module provides Jest compatible expect assertion functionality.
import { expect } from "@ende/expect";
const x = 6 * 7;
expect(x).toEqual(42);
expect(x).not.toEqual(0);
await expect(Promise.resolve(x)).resolves.toEqual(42);
Currently this module supports the following functions:
- Common matchers:
toBetoEqualtoStrictEqualtoMatchtoMatchObjecttoBeDefinedtoBeUndefinedtoBeNulltoBeNaNtoBeTruthytoBeFalsytoContaintoContainEqualtoHaveLengthtoBeGreaterThantoBeGreaterThanOrEqualtoBeLessThantoBeLessThanOrEqualtoBeCloseTotoBeInstanceOftoThrowtoHavePropertytoMatchSnapshottoMatchInlineSnapshot
- Mock related matchers:
toHaveBeenCalledtoHaveBeenCalledTimestoHaveBeenCalledWithtoHaveBeenLastCalledWithtoHaveBeenNthCalledWithtoHaveReturnedtoHaveReturnedTimestoHaveReturnedWithtoHaveLastReturnedWithtoHaveNthReturnedWith
- Asymmetric matchers:
expect.anythingexpect.anyexpect.arrayContainingexpect.not.arrayContainingexpect.objectContainingexpect.not.objectContainingexpect.closeToexpect.stringContainingexpect.not.stringContainingexpect.stringMatchingexpect.not.stringMatching
- Utilities:
expect.addSnapshotSerializerexpect.assertionsexpect.addEqualityTesterexpect.extendexpect.hasAssertions
Only these functions are still not available:
- Matchers:
toThrowErrorMatchingSnapshottoThrowErrorMatchingInlineSnapshot
The tracking issue to add support for unsupported parts of the API is https://github.com/denoland/std/issues/3964.
This module is largely inspired by x/expect module by Allain Lalonde.
Modules
@ende/expect/expect@ende/expect/fn— This module contains a function to mock functions for testing and assertions.
Exports
AnyConstructor— A constructor that accepts any args and returns any valueAsync— converts all the methods in an interface to be async functionsexpect— **Note:** the documentation for this module is taken from Jest and the examples are updated for Ende.Expected— The Expected interface defines the available assertion methods.ExpectSnapshotState— State for snapshot testing, following Jest's `expect.getState()`/`expect.setState()` API.fn— Creates a mock function that can be used for testing and assertions.