method
test.Expect.addSnapshotSerializer
): void;
Registers a serializer for the snapshot matchers. It prints every value that serializer.test() returns true for, anywhere in a snapshot. The most recently added serializer is tried first.
A serializer added by a test file lasts until that file ends. One added by a preload script, or by a module that test files import, applies to every file after it.
expect.addSnapshotSerializer({
test: value => value instanceof Money,
serialize: value => `${value.amount} ${value.currency}`,
});
expect({ price: new Money(5, "EUR") }).toMatchInlineSnapshot(`
{
"price": 5 EUR,
}
`);Referenced types
type SnapshotSerializer = { test(value: any): boolean } & { serialize(value: any, config: SnapshotSerializerConfig, indentation: string, depth: number, refs: unknown[], printer: SnapshotPrinter): string } | { print(value: any, print: (value: unknown) => string, indent: (text: string) => string): string }
A pretty-format plugin for Expect.addSnapshotSerializer. Either of the two plugin interfaces works.