import { expect, not, toEqual } from "@testingrequired/expect";
expect(10, toEqual(10));
expect("foo", not(toEqual("bar")));
Invert assertion function:
import { expect, not, toEqual } from "@testingrequired/expect";
expect(10, not(toEqual(100)));
Assert referential equality:
import { expect, toBe } from "@testingrequired/expect";
const value = { foo: "bar" };
expect(value, toBe(value)); // True
expect(value, toBe({ foo: "bar" })); // False
Assert referential equality to undefined
:
import { expect, toBeUndefined } from "@testingrequired/expect";
expect(undefined, toBeUndefined); // True
expect([1, 2, 3], toBeUndefined); // False
Assert referential equality to null
:
import { expect, toBeNull } from "@testingrequired/expect";
expect(null, toBeNull); // True
expect([1, 2, 3], toBeNull); // False
Assert referential equality to true
:
import { expect, toBeTrue } from "@testingrequired/expect";
expect(true, toBeTrue); // True
expect(1, toBeTrue); // False
expect([1, 2, 3], toBeTrue); // False
Assert truthy value:
import { expect, toBeTruthy } from "@testingrequired/expect";
expect(true, toBeTruthy); // True
expect([1, 2, 3], toBeTruthy); // True
expect(0, toBeTruthy); // False
Assert referential equality to false
:
import { expect, toBeFalse } from "@testingrequired/expect";
expect(false, toBeFalse); // True
expect(0, toBeFalse); // False
expect([1, 2, 3], toBeFalse); // False
Assert truthy value:
import { expect, toBeFalsy } from "@testingrequired/expect";
expect(false, toBeFalsy); // True
expect(0, toBeFalsy); // True
expect(1, toBeFalsy); // False
Assert equality to instanceof
:
import { expect, toBeInstanceOf } from "@testingrequired/expect";
class CustomError extends Error {}
const error = new CustomError();
expect(error, toBeInstanceOf(CustomError)); // True
expect(error, toBeInstanceOf(Error)); // True
expect(error, toBeInstanceOf(String)); // False
Assert value equality:
import { expect, toEqual } from "@testingrequired/expect";
expect(10, toEqual(10)); // True
expect({ foo: "bar" }, toEqual({ foo: "bar" })); // True
Assert function throws error:
import { expect, toThrow } from "@testingrequired/expect";
class CustomError extends Error {}
const expectedErrorMessage = "expectedErrorMessage";
const fn = () => {
throw new CustomError(expectedErrorMessage);
};
expect(fn, toThrow()); // True
expect(fn, toThrow(expectedErrorMessage)); // True
expect(fn, toThrow(new CustomError(expectedErrorMessage))); // True