Your first snapshots

insta macros

To work with snapshots, we need to use insta's assertion macros.
There's one macro for each format we want to compare:

  • assert_snapshot! for strings
  • assert_debug_snapshot! to compare the Debug representation of a value with a snapshot
  • assert_display_snapshot! to compare the Display representation of a value with a snapshot
  • assert_json_snapshot! to compare JSON values
  • etc. for other formats (check the documentation for a complete list)

You always want to use the most specific macro available, since it will give you better error messages thanks to the more specific comparison logic.

insta review

The key command exposed by insta's CLI is cargo insta review.
It will compare the snapshots generated by your last test run with the ones you had previously saved.

Exercise

The exercise for this section is located in 02_snapshots/01_snapshots