Skip to main content

@rbxts/expect > ExpectMessageBuilder > expectedType

ExpectMessageBuilder.expectedType() method

Sets a value to use for the .

Signature:

expectedType(typeStr?: string): this;

Parameters

Parameter

Type

Description

typeStr

string

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

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 expected 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.name} to ${place.not} equal ${place.expected.value} (${place.expected.type})`
);

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

if(isMyCustomType(expected)) {
message.expectedType("MyCustomType");
// ...
}
};

Example output:

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