Skip to content

Conversation

@dylanbr
Copy link

@dylanbr dylanbr commented Jan 22, 2026

As per the issue I previously already, here is an implementation of named snapshots, option 2.

Having the option to use explicitly named IDs for snapshots allows one to avoid needing read confusing diffs when a test is refactored (see the issue for an example).

This PR implements the following changes:

  • Moves the incrementor functionality to the SnapshotIdAware concern. It makes sense to have it here, rather than in MatchesSnapshots, so getting an ID and incrementing are all a single operation.
  • Added an optional $id argument to all the assertions. The retains backwards compatibility, while allowing explicit IDs to be used when required.
  • When the optional $id is populated, this is used to name the snapshot, instead of the next incrementor value. It is also prefixed with s- to avoid the possibility of conflicts with incrementor values.
  • Adds additional tests for all the assertions with the optional $id argument set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant