Skip to main content

@rbxts/expect > ExpectMessageBuilder > index

ExpectMessageBuilder.index() method

Sets a value for the index placeholder.

Signature:

index(index?: number | string): this;

Parameters

Parameter

Type

Description

index

number | string

(Optional)

Returns:

this

This instance, for chaining.

Remarks

Usually, indexies are attached as metadata, but sometimes you might also want to show the index in your message.

That's where the index placeholder comes into play.

Example

For example, lets say we were testing if two arrays are equal.

new ExpectMessageBuilder(
`Expected the array ${place.actual.value} to ${place.not} equal ${place.expected.value}`
).failureSuffix(`, but the ${place.index}nth element ${place.reason}`);

We might use logic like so:

for(const [index, value] of ipairs(actual)) {
if(expected[index] !== actual[index]) {
return message.failWithReason("had a different value");
}
}

Which would result in the following output:

Expected the array [1,2,3] to equal [1,2,4], but the 3nth element had a different value