Support code block formatting for string snapshots
Author: novemberbornCreated May 3, 2026Updated May 3, 2026
Labelsenhancementscope:assertions
As an overload in SnapshotAssertion: https://github.com/avajs/ava/blob/a6f42ea472cfbe7047a0fb89ab0cd728b4e04ae1/types/assertions.d.cts#L320-L332)
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 https://github.com/avajs/ava/discussions/2903#discussioncomment-13017478
Source: avajs/ava