Module

std/expect/mod.ts

The Deno Standard Library
Go to Latest
import * as mod from "https://dotland.deno.dev/std@0.223.0/expect/mod.ts";

This module provides Jest compatible expect assertion functionality.

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
    • toHaveLength
  • 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.closeTo
    • expect.stringContaining
    • expect.not.stringContaining
    • expect.stringMatching
    • expect.not.stringMatching
  • Utilities:
    • expect.addEqualityTester
    • expect.extend

Only these functions are still not available:

  • Matchers:
    • toMatchSnapShot
    • toMatchInlineSnapShot
    • toThrowErrorMatchingSnapShot
    • toThrowErrorMatchingInlineSnapShot
  • Asymmetric matchers:
    • expect.objectContaining
    • expect.not.objectContaining
  • Utilities:
    • expect.assertions
    • expect.hasAssertions
    • expect.addSnapshotSerializer

This module is largely inspired by x/expect module by Allain Lalonde.

Examples

Example 1

import { expect } from "https://deno.land/std@0.223.0/expect/mod.ts";

const x = 6 * 7;
expect(x).toEqual(42);
expect(x).not.toEqual(0);

await expect(Promise.resolve(x)).resolves.toEqual(42);