Skip to content

Support code block formatting for string snapshots #3441

Description

@novemberborn

As an overload in SnapshotAssertion:

ava/types/assertions.d.cts

Lines 320 to 332 in a6f42ea

export type SnapshotAssertion = {
/**
* Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
* previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if
* necessary record a new snapshot.
*
* Returns `true` if the assertion passed and throws otherwise.
*/
(expected: any, message?: string): true;
/** Skip this assertion. */
skip(expected: any, message?: string): void;
};
)

snapshot(expected: string, options?: { formatAsCodeBlock: true | string }, message?: string)

This options object should only be accepted for string values, and must only contain formatAsCodeBlock. string values would be the syntax, and true would be the same as an empty string (but less weird).

When formatting, backticks would need to be escaped properly.

Originally posted by @novemberborn in #2903 (reply in thread)

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions