Skip to main content
Deno 2 is finally here ๐ŸŽ‰๏ธ
Learn more
Module

x/unitest/matcher/to_be_within.ts>toBeWithin

๐Ÿƒ Deno-first universal unit testing framework
Latest
function toBeWithin
import { toBeWithin } from "https://deno.land/x/unitest@v1.0.0-beta.82/matcher/to_be_within.ts";

Use .toBeWithin when checking if a number is in between the given bounds of: start (inclusive) and end (exclusive)

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

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

test("passes when number is within given bounds", () => {
  expect(1).toBeWithin(1, 3);
  expect(2).toBeWithin(1, 3);
  expect(3).not.toBeWithin(1, 3);
});

Parameters

actual: number
start: number
end: number