Jest snapshots not matching - Windows vs Unix/Linux Line Endings Jest snapshots not matching - Windows vs Unix/Linux Line Endings reactjs reactjs

Jest snapshots not matching - Windows vs Unix/Linux Line Endings


The best way to synchronize something like this across a team is to use EditorConfig. Most code editors support it, either natively or through an extension.

EditorConfig is a universal way to specify editor setting, Line Endings in your case, that is respected by all code editors on all OSes.

https://editorconfig.org

# Unix-style newlines with a newline ending every file[*]end_of_line = lf


We are using snapshot serializer in our project to avoid such issues, it should help in your case too. For html snapshots I recommend jest-serializer-html


We had the exact same issue where Windows machines were generating snapshots with different line breaks than Macs.

We found out that VS Code was set to LF line break settings on the windows machine and changing to CRLF fixed the issue.

I'd recommend checking line ending settings in your editors and anywhere else earlier in the chain.