@rbxts/expect > ExpectMessageBuilder > surfaceMetadata
ExpectMessageBuilder.surfaceMetadata() method
Attach data to follow after the main message, in the format of key: value
.
Only attached when the message does NOT have a path.
Signature:
surfaceMetadata(data: Record<string, unknown>): this;
Parameters
Parameter | Type | Description |
---|---|---|
data | Record<string, unknown> | An object of |
Returns:
this
This instance, for chaining.
Remarks
The same as metadata, but is limited to only messages without paths.
Useful for when you wanna conditionally attach data, but only when the case is on non nested objects.
Will come before all other metadata types (if any).
Note that this merges with any existing surface metadata, so you can safely call this multiple times to add more data or overwrite previous data
Example
For example, let's say we were checking if an object was empty, and we wanted to use the name the object
to keep the message short:
const baseMessage = new ExpectMessageBuilder(
`Expected ${place.name} to ${place.not} be empty`
)
.name("the object")
.nestedMetadata({ [place.path]: place.actual.value });
We might have logic like so:
if (amount > 1) {
return message
.suffix(`, but it had ${amount} keys`)
.surfaceMetadata({ Value: place.actual.value })
.fail();
}
Example output for messages without a path:
Expected the object to be empty, but it had 2 keys
Value: '{"name":"Daymon","age":24}'
Example output for messages with a path:
Expected parent.parent to be empty, but it had 2 keys
parent.parent: '{"name":"Daymon","age":24}'