Skip to main content

@rbxts/expect > ExpectMessageBuilder > use

ExpectMessageBuilder.use() method

Create a copy of this instance, to be populated with data.

Signature:

use(trailingPrefix?: string, trailingFailurePrefix?: string): ExpectMessageBuilder;

Parameters

Parameter

Type

Description

trailingPrefix

string

(Optional) An additional string to add at the end of the existing prefix (including the negation prefix).

trailingFailurePrefix

string

(Optional) An additional string to add at the end of the existing prefix, but only in the case of failure (replaces the existing trailingFailurePrefix).

Returns:

ExpectMessageBuilder

A new copy of this instance, ready to be used.

Remarks

This is the primary entry point into using a message.

Since data attached to an ExpectMessageBuilder persists, if you don't create a copy of the instance in your method, the next caller will still have that data in their message.

Example

const baseMessage = new ExpectMessageBuilder(
`Expected ${place.name} to ${place.not} equal ${place.expected.value}`
);

const equal: CustomMethodImpl<defined> = (
_,
actual: defined,
expected: defined
) => {
const message = baseMessage.use().expectedValue(expected);

return actual === expected ? message.pass() : message.fail();
};