Skip to main content

@rbxts/expect > ExpectMessageBuilder > actualType

ExpectMessageBuilder.actualType() method​

Sets a value to use for the .

Signature:

actualType(typeStr?: string): this;

Parameters​

Parameter

Type

Description

typeStr

string

(Optional) The type of the actual variable as a string, or undefined to reset it (defaults to the typeOf of the actualValue).

Returns:

this

This instance, for chaining.

Remarks​

You usually don't need to set this yourself.

This comes in handy when you wanna provide additional type information about the actual type.

The method is a perfect example of this; where the type for enum values becomes enum/number instead of number.

Example​

Lets say we were checking if types are equal, but wanted to support a custom class:

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

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

if(isMyCustomType(actual)) {
message.actualType("MyCustomType");
// ...
}
};

Example output:

Expected "4" (number) to equal '4'
Expected '{"name":"Daymon"}' (MyCustomType) to equal '{"name":"Bryan"}'