Skip to main content

@rbxts/expect > Assertion > enum

Assertion.enum() method

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

Signature:

enum<R>(enumType: R & Record<number, string>, value: keyof R): Assertion<EnumValue<R>>;

Parameters

Parameter

Type

Description

enumType

R & Record<number, string>

A TS defined enum or an equivalent record in lua.

value

keyof R

The expected value of the defined enum type, as a key string.

Returns:

Assertion<EnumValue<R>>

Remarks

This is not for ROBLOX specific enums, but for user defined enums.

The reason you would use this over equal, is that enum not only throws more descriptive errors about enums, but it also attaches the enum_type property for chained methods to provide their own more descriptive errors about enums.

Example

enum Sport {
Basketball,
Football,
Soccer
}

expect(Sport.Basketball).to.be.the.enum(Sport, "Basketball");
expect("Basketball").to.be.the.enum(Sport, "Basketball");
expect(0).to.be.the.enum(Sport, "Basketball");