Objects
API
Is an Object
You can use the object method to check if a provided value is actually an object.
import { expect } from "@rbxts/expect";
expect({ name: "Daymon" }).to.be.an.object();
Example error
Expected '5' to be of type 'table', but it was a 'number'
Empty
You can use the empty method to check if an object contains any keys.
import { expect } from "@rbxts/expect";
expect({}).to.be.empty();
Example error
Expected the object to be empty, but it had had the key 'name'
Value of [name]: "Daymon"
Length
You can use the length method to check if an object has a certain amount of keys.
import { expect } from "@rbxts/expect";
expect({
name: "Daymon",
age: 24,
}).to.have.a.lengthOf(2);
Example error
Expected the object to have exactly '3' key(s), but it actually had '2'
Value: '{"name":"Daymon","age":24}'
Deep equal
You can use the deepEqual method to check if two objects are deeply equal to one another.
import { expect } from "@rbxts/expect";
expect({
name: "Daymon",
age: 5,
}).to.deepEqual({
name: "Daymon",
age: 5,
});
Example error
Expected '{...}' to deep equal '{...}', but 'age' has a different value
Expected: '4' (number)
Actual: '5' (number)
Expected (full): '{"name":"Daymon","age":4}'
Actual (full): '{"name":"Daymon","age":5}'
Match
You can use the match method to check if an object has a collection of certain keys with certain values.
import { expect } from "@rbxts/expect";
expect({
name: "Daymon",
age: 5,
}).to.match({
age: 5,
});
Example error
Expected '{...}' to match '{...}', but 'age' has a different value
Expected: '4' (number)
Actual: '5' (number)
Expected (full): '{"age":4}'
Actual (full): '{"name":"Daymon","age":5}'
Key/Property
You can use the key or property methods to check if an object has a certina key.
import { expect } from "@rbxts/expect";
expect({
name: "Daymon",
age: 5,
}).to.have.the.key("name");
Example error
Expected '{...}' to have the key "parent", but it was missing
Actual (full): '{"name":"Daymon","age":5}'
Extra
Proxies allow you to provide the path of nested variables in your test output.