This is a useful serializer plugin for Jest snapshot testing to give more readable snapshot outputs and improve your tests based on the Testing Best Practices, and which uses the Pretty Format library.
For the moment, you can use it by doing a fork and installing the dependencies or by copying the snapshotSerializer.
You will need to configure it in your Jest configuration file.
Here's an example:
Once you have configured the plugin, any snapshot tests that are run with Jest will use the pretty-format serializer.
Here's an example test that uses the serializer to generate a more readable snapshot output:
As you can see, the output is much easier to read and understand than the default snapshot output.
Also, with this plugin we filter useless attributes and we avoid to update the snapshot any time we have modified the attributes.
You can to exclude certain attributes from the serialized output. You can do this by adding the attributes to the VALID_ATTRIBUTES constant of the serializer.
With the snapshot serializer plugin using pretty-format, Jest snapshot tests become much more readable and easier to understand. In addition, we filter out the attributes that are not needed to avoid having to update the snapshot every time we modify the attributes of an element. You can tailor the output to your specific needs.