Skip to main content

@rbxts/expect > Assertion

Assertion interface

Parent interface for all expect() calls.

Signature:

interface Assertion<T = unknown> 

Remarks

When a call to expect() is made, the returned value is an instance of this interface.

It provides a common means for all the methods to be attached.

You can think of it as an instance of expect(), or a controller of sorts.

Although, expect() is designed with the idea of call-when-you-need in mind. That is, it's not expected that you'd save the result of an expect() call, and then re-call it at some point down the line.

For example:

// DONT do this
const assertion = expect(5);
assertion.to.be.number();
assertion.to.equal(5);

// Do this
expect(5).to.be.a.number().that.equals(5);

// Or this
const actual = 5;
expect(actual).to.be.a.number();
expect(actual).to.equal(5);

Properties

Property

Modifiers

Type

Description

a

readonly

this

NOOP property for cleaner chaining; does nothing.

also

readonly

this

NOOP property for cleaner chaining; does nothing.

an

readonly

this

NOOP property for cleaner chaining; does nothing.

and

readonly

this

NOOP property for cleaner chaining; does nothing.

at

readonly

this

NOOP property for cleaner chaining; does nothing.

be

readonly

this

NOOP property for cleaner chaining; does nothing.

been

readonly

this

NOOP property for cleaner chaining; does nothing.

but

readonly

this

NOOP property for cleaner chaining; does nothing.

does

readonly

this

NOOP property for cleaner chaining; does nothing.

enum_type?

Record<number, string>

(Optional) Helper property for getting the mappings for a value that has passed an check.

have

readonly

this

NOOP property for cleaner chaining; does nothing.

is_array?

boolean

(Optional) Helper property for checking if a value has already passed an check.

is

readonly

this

NOOP property for cleaner chaining; does nothing.

never

readonly

this

Negates the assertion.

not

readonly

this

Negates the assertion.

of

readonly

this

NOOP property for cleaner chaining; does nothing.

or

readonly

this

NOOP property for cleaner chaining; does nothing.

still

readonly

this

NOOP property for cleaner chaining; does nothing.

that

readonly

this

NOOP property for cleaner chaining; does nothing.

the

readonly

this

NOOP property for cleaner chaining; does nothing.

to

readonly

this

NOOP property for cleaner chaining; does nothing.

value

readonly

T

The "actual" value attached to this expect() call.

which

readonly

this

NOOP property for cleaner chaining; does nothing.

Methods

Method

Description

above(value)

Asserts that the value is greater than value.

all(condition)

Asserts that all elements in the array satisfy the specified Filter.

all(reason, condition)

Asserts that all elements in the array satisfy the specified Filter.

anyOf(values)

Asserts that the value is shallow equal to any of the provided values.

array()

Asserts that the value is an array.

array(typeName)

Asserts that the value is an array of type typeName.

array(checker)

Asserts that the value is an array of type I, according to a custom callback TypeCheckCallback.

array(tChecker)

Asserts that the value is an array of type I, according to a provided t check.

arrayOf(typeName)

Asserts that the value is an array of type typeName.

arrayOf(checker)

Asserts that the value is an array of type I, according to a custom callback TypeCheckCallback.

arrayOf(tChecker)

Asserts that the value is an array of type I, according to a provided t check.

below(value)

Asserts that the value is less than value.

between(minValue, maxValue)

Asserts that the actual value is a number within a specified range.

boolean()

Asserts that the value is a boolean.

closeTo(value)

Asserts that the actual value is a number within epsilon of value.

closeTo(value, margin)

Asserts that the actual value is a number within margin of value.

containExactly(expectedValues)

Asserts that the array contains all of the values in expectedValues, and nothing more or less.

containExactlyInOrder(expectedValues)

Asserts that the array contains all of the values in expectedValues, with nothing more or less, and in the same order.

containsExactly(expectedValues)

Asserts that the array contains all of the values in expectedValues, and nothing more or less.

containsExactlyInOrder(expectedValues)

Asserts that the array contains all of the values in expectedValues, with nothing more or less, and in the same order.

deepEqual(expectedValue)

Asserts that the value is deep equal to the expectedValue.

deepEquals(expectedValue)

Asserts that the value is deep equal to the expectedValue.

defined()

Asserts that the actual value is a non null value.

empty()

Asserts that the value is empty.

endsWith(elements)

Asserts that the array ends with the specified elements.

endsWith(str)

Asserts that the actual value is a string that ends with the specified string.

endWith(elements)

Asserts that the array ends with the specified elements.

endWith(str)

Asserts that the actual value is a string that ends with the specified string.

enum(enumType)

Asserts that the value is an enum of type R.

enum(enumType, value)

Asserts that the value is an enum of type R, and equal to the value.

enum(enumType, value)

Asserts that the value is an enum of type R, and equal to the value.

eq(expectedValue)

Asserts that the value is shallow equal to the expectedValue.

eql(expectedValue)

Asserts that the value is deep equal to the expectedValue.

equal(expectedValue)

Asserts that the value is deep equal to the expectedValue.

equals(expectedValue)

Asserts that the value is deep equal to the expectedValue.

even()

Asserts that the actual value is an even number.

exist()

Asserts that the actual value is a non null value.

exists()

Asserts that the actual value is a non null value.

false()

Asserts that the value is a boolean of false.

falsy()

Asserts that the value is a "falsy" value, according to luau.

finite()

Asserts that the actual value is a number within +-math.huge.

function()

Asserts that the value is a function.

greaterThan(value)

Asserts that the value is greater than value.

greaterThanOrEqualTo(value)

Asserts that the value is greater than or equal to value.

gt(value)

Asserts that the value is greater than value.

gte(value)

Asserts that the value is greater than or equal to value.

include(expectedValue)

Asserts that the expectedValue is a value in the array.

includes(expectedValue)

Asserts that the expectedValue is a value in the array.

instanceOf(name)

Asserts that the value is an instance of type typeName.

instanceOf(checker)

Asserts that the value is an instance of I, according to a custom callback TypeCheckCallback.

instanceOf(tChecker)

Asserts that the value is an instance of I, according to a provided t check.

key(key)

Asserts that the table has the key key.

least(value)

Asserts that the value is greater than or equal to value.

length(size)

Asserts that the value has a length of size.

lengthOf(size)

Asserts that the value has a length of size.

lessThan(value)

Asserts that the value is less than value.

lessThanOrEqualTo(value)

Asserts that the value is less than or equal to value.

lt(value)

Asserts that the value is less than value.

lte(value)

Asserts that the value is less than or equal to value.

match(expected)

Asserts that the actual value has the same properties and values as the expected.

matches(expected)

Asserts that the actual value has the same properties and values as the expected.

matchExactly(expectedValue)

Asserts that the value is deep equal to the expectedValue.

most(value)

Asserts that the value is less than or equal to value.

near(value)

Asserts that the actual value is a number within epsilon of value.

near(value, margin)

Asserts that the actual value is a number within margin of value.

negative()

Asserts that the value is a negative number.

nil()

Asserts that the actual value is a null value.

null()

Asserts that the actual value is a null value.

number()

Asserts that the value is a number.

object()

Asserts that the value is a table.

odd()

Asserts that the actual value is an odd number.

ok()

Asserts that the actual value is a non null value.

oneOf(values)

Asserts that the value is shallow equal to one of the provided values.

pattern(pattern)

Asserts that the expectedValue is a string that contains a match for the provided lua pattern.

positive()

Asserts that the value is a positive number.

property(property)

Asserts that the table has the property property.

satisfies(filter)

Asserts that the value returns true for the given filter.

satisfy(filter)

Asserts that the value returns true for the given filter.

shallowEqual(expectedValue)

Asserts that the value is shallow equal to the expectedValue.

shallowEquals(expectedValue)

Asserts that the value is shallow equal to the expectedValue.

size(size)

Asserts that the value has a length of size.

sizeOf(size)

Asserts that the value has a length of size.

some(condition)

Asserts that at least one element in the array satisfies the specified Filter.

some(reason, condition)

Asserts that at least one element in the array satisfies the specified Filter.

startsWith(elements)

Asserts that the array starts with the specified elements.

startsWith(str)

Asserts that the actual value is a string that starts with the specified string.

startWith(elements)

Asserts that the array starts with the specified elements.

startWith(str)

Asserts that the actual value is a string that starts with the specified string.

string()

Asserts that the value is a string.

substring(str)

Asserts that the string value contains the string str.

table()

Asserts that the value is a table.

throw()

Asserts that the function throws an exception.

throw(substring)

Asserts that the function throws an exception that contains the string substring.

throwMatch(pattern)

Asserts that the function throws an exception that matches the lua pattern pattern.

throws()

Asserts that the function throws an exception.

throws(substring)

Asserts that the function throws an exception that contains the string substring.

throwsMatch(pattern)

Asserts that the function throws an exception that matches the lua pattern pattern.

true()

Asserts that the value is a boolean of true.

truthy()

Asserts that the value is a "truthy" value, according to luau.

typeOf(name)

Asserts that the value is of type typeName.

typeOf(checker)

Asserts that the value is of type I, according to a custom callback TypeCheckCallback.

typeOf(tChecker)

Asserts that the value is of type I, according to a provided t check.

undefined()

Asserts that the actual value is a null value.

within(minValue, maxValue)

Asserts that the actual value is a number within a specified range.