Skip to main content

Basic

This page contains matchers that apply to all types.

API

Any of

You can use the anyOf method to check if a provided value is shallowly equal to one of the values in an array.

import { expect } from "@rbxts/expect";

expect(1).to.be.anyOf([1, 2, 3]);

Example error

Expected '5' (number) to be any of '[1,2,3,4]'

Equal

You can use the equals method to check if a provided value is strictly equal to another value.

import { expect } from "@rbxts/expect";

expect(1).to.equal(1);

Example error

Expected '5' (number) to strictly equal "5" (string)

Instance of

You can use the instanceOf method to check if a provided value is of a certain type.

This includes support for checkable types, t checks, and even user-defined callbacks.

import { expect, TypeCheckCallback } from "@rbxts/expect";
import t from "@rbxts/t";

const isNumber: TypeCheckCallback = (value) => {
return typeOf(value) === "number";
};

expect(1).to.be.an.instanceOf("number");
expect(1).to.be.an.instanceOf(t.number);
expect(1).to.be.an.instanceOf(isNumber);

Example error

Expected '5' to be of type 'string', but it was a 'number'

Satisfy

You can use the satisfy method to check if a provided value passes a given callback.

import { expect } from "@rbxts/expect";

expect(4).to.satisfy((value) => 4 % 2 === 0);

Example error

Expected '5' (number) to satisfy a given callback, but it didn't

Defined

You can use the defined method to check if a provided value is not null.

import { expect } from "@rbxts/expect";

expect(1).to.be.defined();
expect(1).to.be.ok();
expect(1).to.exist();

expect(undefined).to.not.be.defined();

Example error

Expected the value to be defined, but it was undefined

Undefined

You can use the undefined method to check if a provided value is null.

import { expect } from "@rbxts/expect";

expect(undefined).to.be.undefined();
expect(undefined).to.be.null();
expect(undefined).to.be.nil();

expect(5).to.not.be.undefined();

Example error

Expected '5' (number) to be undefined, but it was defined