Unitest Beta

dummy

dummy provides dummy object. The dummy object is the only specially processed object in the equal function.

The dummy object can be used to perform asymmetric matching.

anything

anything() matches anything but null or undefined.

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

test("should not be null or undefined", () => {
  expect(actual).toEqual(anything());
});

any

any(constructor) matches anything that was created with the given constructor.

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

test("should be any number", () => {
  expect(Infinity).toEqual(any(Number));
});

arrayContaining

arrayContaining(array) matches a received array which contains all of the elements in the expected array.

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

test("should be any number", () => {
  expect(["Alice", "Bob", "Eve"]).toEqual(arrayContaining(["Eve", "Bob"]));
});

objectContaining

objectContaining(object) matches any received object that recursively matches the expected properties

import {
  any,
  expect,
  objectContaining,
  test,
} from "https://deno.land/x/unitest@$VERSION/mod.ts";

test("should be any number", () => {
  expect({
    name: "Bob",
    score: 100,
  }).toEqual({
    name: any(String),
    score: any(Number),
  });
});

stringMatching

stringMatching(string | RegExp) matches string or regular expression

import {
  any,
  expect,
  stringMatching,
  test,
} from "https://deno.land/x/unitest@$VERSION/mod.ts";

test("should be match pattern", () => {
  expect("hello! This is a good day.").toEqual(stringMatching(/good/));
});

stringContaining

stringMatching(string) matches if string contains

import {
  any,
  expect,
  stringMatching,
  test,
} from "https://deno.land/x/unitest@$VERSION/mod.ts";

test("should contain pattern", () => {
  expect("hello! This is a good day.").toEqual(stringMatching("good"));
});

anyString

anyString() matches any string or String

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

test("should be any string", () => {
  expect("hello").toEqual(anyString());
});

anyNumber

anyNumber() matches any number or Number

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

test("should be any number", () => {
  expect(Infinity).toEqual(anyNumber());
});

anyBoolean

anyBoolean() matches any boolean or Boolean

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

test("should be any boolean", () => {
  expect(new Boolean(false)).toEqual(anyBoolean());
});

anyArray

anyArray(?unknown) matches any array or any specific array

import {
  anyArray,
  anyString,
  expect,
  test,
} from "https://deno.land/x/unitest@$VERSION/mod.ts";

test("should be any array", () => {
  expect({ students: ["Alice", "Bob", "John"] }).toEqual({
    students: anyArray(),
  });
});

test("should be any string array", () => {
  expect({ students: ["Alice", "Bob", "John"] }).toEqual({
    students: anyArray(anyString()),
  });
});

anyOf

anyOf(array) matches any of expected value

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

test("should be any of 1, 2, 3", () => {
  expect(3).toEqual(anyOf([1, 2, 3]));
});