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()
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("").toEqual(anything());
expect(null).not.toEqual(anything());
expect(undefined).not.toEqual(anything());
});
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(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(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(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/));
});
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()
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());
});
anyString
accept condition function. You can put conditions on the
equivalence.
import {
anyString,
expect,
test,
} from "https://deno.land/x/unitest@$VERSION/mod.ts";
const isUpper = (value: string): boolean => /^[A-Z]+$/.test(value);
test("should be upperCase string", () => {
expect("HELLO").toEqual(anyString(isUpper));
});
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());
});
anyNumber
accept condition function. You can put conditions on the
equivalence.
import {
anyNumber,
expect,
test,
} from "https://deno.land/x/unitest@$VERSION/mod.ts";
import { isEven } from "https://deno.land/x/isx/mod.ts";
test("should be even", () => {
expect(2).toEqual(anyNumber(isEven));
});
anyNumber()
matches any bigint
or BigInt
.
import {
anyBigInt,
expect,
test,
} from "https://deno.land/x/unitest@$VERSION/mod.ts";
test("should be any bigint", () => {
expect(1n).toEqual(anyBigInt());
});
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());
});
anyBoolean()
matches any symbol
or Symbol
import {
anySymbol,
expect,
test,
} from "https://deno.land/x/unitest@$VERSION/mod.ts";
test("should be any symbol", () => {
expect(Symbol.for("symbol")).toEqual(anySymbol());
});
anyFunction()
matches any function
.
import {
anyFunction,
expect,
test,
} from "https://deno.land/x/unitest@$VERSION/mod.ts";
test("should be any function", () => {
expect(() => {}).toEqual(anyFunction());
});
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(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]));
});