Skip to main content
Module

x/unitest/mod.ts>toSatisfy

🃏 Deno-first universal unit testing framework
Latest
function toSatisfy
Re-export
import { toSatisfy } from "https://deno.land/x/unitest@v1.0.0-beta.82/mod.ts";

Use .toSatisfy when you want to use a custom matcher by supplying a predicate function that returns a boolean.

import {
  defineExpect,
  not,
  test,
  toSatisfy,
} from "https://deno.land/x/unitest@$VERSION/mod.ts";

const expect = defineExpect({
  matcherMap: {
    toSatisfy,
  },
  modifierMap: {
    not,
  },
});

test("passes when value passes given predicate", () => {
  const greaterThanOneButNotThree = (n: unknown) =>
    typeof n === "number" && n > 1 && n !== 3;
  expect(100).toSatisfy(greaterThanOneButNotThree);
  expect(0).not.toSatisfy(greaterThanOneButNotThree);
  expect(3).not.toSatisfy(greaterThanOneButNotThree);
});

Parameters

actual: unknown
predicate: (actual: unknown) => boolean