@rbxts/expect > ExpectMessageBuilder > actualValue
ExpectMessageBuilder.actualValue() method
Sets a value to use for the actual value.
Signature:
actualValue(value?: unknown): this;
Parameters
Parameter | Type | Description |
---|---|---|
value | unknown | (Optional) The value of the actual variable. |
Returns:
this
This instance, for chaining.
Remarks
This is automatically set by expect() whenever a message is built, but you can provide your own if you need to.
This can come in handy when you have additional context, or a better way to represent the "actual" value.
Example
Lets say we were checking if two values are equal, but wanted to support enum values:
const baseMessage = new ExpectMessageBuilder(
`Expected ${place.name} to ${place.not} equal ${place.expected.value}`
);
const equal: CustomMethodImpl<defined> = (
_,
enumTable,
actual: defined,
expected: defined
) => {
const message = baseMessage.use().expectedValue(expected);
const valueAsEnum = enumTable[actual];
message.actualValue(valueAsEnum);
// ...
};
So instead of this output:
Expected '0' to equal "Basketball"
We can get this output:
Expected "Soccer" to equal "Basketball"