Skip to main content

Quick Start

@rbxts/expect is a test-agnostic assertion library for ROBLOX, enabling assertions in tests or server-side code without test dependencies, featuring descriptive error messages.

This guide will walk you through the basics of getting started, in just a few steps.

Installation

First, install @rbxts/expect with your preferred package manager:

Terminal
npm install @rbxts/expect

Start using @rbxts/expect

Once installed, you can immediately start by calling expect.

Arrays

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

expect([1, 2, 3]).to.be.an.array().that.includes(4).but.does.not.include(5);
Console
Expected '[1,2,3]' to include '4', but it was missing
import { expect } from "@rbxts/expect";

expect({ name: "Daymon" }).to.be.an.array();
Console
Expected '{"name": "Daymon"}' to be an array, but it had a non number key 'name' (string)

Strings

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

expect("Daymon").to.be.a.string().with.the.substring("Night");
Console
Expected "Daymon" to have the substring "Night"
import { expect } from "@rbxts/expect";

expect("Daymon").to.not.be.empty().and.to.have.a.sizeOf(5);
Console
Expected "Daymon" to have a size of '5', but it actually had a size of '6'

Enums

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

enum Sport {
Basketball,
Soccer,
Football,
}

expect("Bowling").to.be.the.enum(Sport);
Console
Expected "Bowling" (string) to be a valid enum of '(Basketball | Soccer | Football)'
import { expect } from "@rbxts/expect";

expect(Sport.Basketball).to.be.the.enum(Sport, "Soccer");
Console
Expected 'Basketball' (enum/number) to be the enum 'Soccer'
import { expect } from "@rbxts/expect";

expect(Sport.Basketball).to.be.the.enum(Sport).and.to.be.anyOf(["Soccer", "Football"]);
Console
Expected 'Basketball' (enum/number) to be any of '["Soccer", "Football"]'

Deep equals

tip

You can also use equal, since it points to deepEqual by default!

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

expect(new Vector3(1, 2, 3)).to.deepEqual(new Vector3(1, 2, 3)); // pass!
expect(new Vector3(1, 2, 3)).to.deepEqual(new Vector3());
Console
Expected '1, 2, 3' to deep equal '0, 0, 0', but they have different values

Expected: '0, 0, 0' (Vector3)
Actual: '1, 2, 3' (Vector3)
import { expect } from "@rbxts/expect";

expect({
name: "daymon",
age: 24,
child: {
name: "nova",
age: 5,
},
}).to.deepEqual({
name: "daymon",
age: 24,
child: {
name: "rigby",
age: 5,
},
});
Console
Expected '{...}' to deep equal '{...}', but 'child.name' has a different value

Expected: "rigby" (string)
Actual: "nova" (string)

Expected (full): '{"child":{"name":"rigby","age":5},"name":"daymon","age":24}'
Actual (full): '{"child":{"name":"nova","age":5},"name":"daymon","age":24}'

Custom messages

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

expect(5, "You don't have enough money!").to.be.gte(10);
Console
You don't have enough money!

Next steps

If you're wanting to learn more, feel free to check out any of the following resources: