@rbxts/expect > ExpectMessageBuilder > nestedMetadata
ExpectMessageBuilder.nestedMetadata() method
Attach data to follow after the main message, in the format of key: value
.
Only attached when the message has a path.
Signature:
nestedMetadata(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 with paths.
Useful for when you wanna conditionally attach data, but only when the case is on nested objects.
Will come before all other metadata types (if any).
Note that this merges with any existing nested metadata, so you can safely call this multiple times to add more data or overwrite previous data
Example
A very common use-case is attaching data about the actual value for nested objects, so you still get the path to the variable in the initial message.
const baseMessage = new ExpectMessageBuilder(
`Expected ${place.name} to ${place.not} equal ${place.expected.value} (${place.expected.type})`
)
.name(`${place.actual.value} (${place.actual.type})`)
.nestedMetadata({
[place.path]: `${place.actual.value} (${place.actual.type})`,
});
Example output for messages without a path:
Expected '5' (number) to equal "5" (string)
Example output for messages with a path:
Expected parent.age to equal "5" (string)
parent.age: '5' (number)