Skip to main content

@rbxts/expect > ExpectMessageBuilder > expectedValue

ExpectMessageBuilder.expectedValue() method

Sets a value to use for the expected value.

Signature:

expectedValue(value?: unknown): this;

Parameters

Parameter

Type

Description

value

unknown

(Optional) The value of the expected variable.

Returns:

this

This instance, for chaining.

Remarks

This is usually the first thing your do when creating a message in your method.

The reason you have to do this yourself, instead of expect() handling it for you- is because your test case may not have an expected value. Or the expected value may not be the first argument.

The method is a perfect example of this; where the first argument is the enum type, and the second argument is the value to check for.

Example

Lets say we were checking if two values are equal:

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);
// ...
};

Example output:

Expected "4" to equal '4'