@ende/expect

ende add jsr:@ende/expect

Version 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:
    • toBe
    • toEqual
    • toStrictEqual
    • toMatch
    • toMatchObject
    • toBeDefined
    • toBeUndefined
    • toBeNull
    • toBeNaN
    • toBeTruthy
    • toBeFalsy
    • toContain
    • toContainEqual
    • toHaveLength
    • toBeGreaterThan
    • toBeGreaterThanOrEqual
    • toBeLessThan
    • toBeLessThanOrEqual
    • toBeCloseTo
    • toBeInstanceOf
    • toThrow
    • toHaveProperty
    • toMatchSnapshot
    • toMatchInlineSnapshot
  • Mock related matchers:
    • toHaveBeenCalled
    • toHaveBeenCalledTimes
    • toHaveBeenCalledWith
    • toHaveBeenLastCalledWith
    • toHaveBeenNthCalledWith
    • toHaveReturned
    • toHaveReturnedTimes
    • toHaveReturnedWith
    • toHaveLastReturnedWith
    • toHaveNthReturnedWith
  • Asymmetric matchers:
    • expect.anything
    • expect.any
    • expect.arrayContaining
    • expect.not.arrayContaining
    • expect.objectContaining
    • expect.not.objectContaining
    • expect.closeTo
    • expect.stringContaining
    • expect.not.stringContaining
    • expect.stringMatching
    • expect.not.stringMatching
  • Utilities:
    • expect.addSnapshotSerializer
    • expect.assertions
    • expect.addEqualityTester
    • expect.extend
    • expect.hasAssertions

Only these functions are still not available:

  • Matchers:
    • toThrowErrorMatchingSnapshot
    • toThrowErrorMatchingInlineSnapshot

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

Exports

  • AnyConstructor — A constructor that accepts any args and returns any value
  • Async — converts all the methods in an interface to be async functions
  • expect — **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.