@rbxts/expect > Placeholder > name
Placeholder.name property
A utility placeholder for either the path, or the actual value.
Messages can configure their own names as well.
Signature:
name: string;
Remarks
A common theme in messages in to display the path when working with tables, and display the actual value when working with non tables.
Using a name
, you can specify to use the path whenever it's available, but fallback to the actual.value.
You can also provide your own name to fallback for instead of the actual value. You can do this via ExpectMessageBuilder.name().
Example
Let's say we were checking if a value was an array:
new ExpectMessageBuilder(
`Expected ${place.name} to be an array`
);
When working with tables, we'd get the following output:
Expected parent.cars to be an array
But when working with non tables, we'd get:
Expected '5' to be an array
It's also a common practice to use nestedMetadata
to provide the "actual" value whenever the path replaces it.
new ExpectMessageBuilder(
`Expected ${place.name} to be an array`
).nestedMetadata({ [place.path]: place.actual.fullValue });
When working with tables, we'd get the following output:
Expected parent.cars to be an array
parent.cars: '5'
But when working with non tables, that additional data wouldn't be there:
Expected '5' to be an array