styled-components / jest-styled-components

šŸ”§ šŸ’… Jest utilities for Styled Components
MIT License
1.59k stars 145 forks source link

Test fails, says there is a difference in the snapshot, but actually there is no difference. #396

Open adbutterfield opened 2 years ago

adbutterfield commented 2 years ago

HI, I have a strange issue (or maybe it's because I'm doing something strange?).

First of all, I'm not sure if this is an issue with this repo, or something in the tooling chain. Please let me know if you think it's not an issue with this wonderful package.

I have a component library, and have just implemented a very paranoid testing strategy, where I run my tests on the build before publishing a new version. I have a bunch of snapshot tests, and for testing the build I simply re-use the snapshots for the tests I run on the non-built components. Everything works great except for one test for one component.

I nailed the issue down to this line here: https://github.com/adbutterfield/jest-snapshot-issue/blob/3ce96e1bc0d228f0959341b4193444791cb7dacc/src/Loading/Loading.styles.ts#L29

Something about the animation is making it fail. If I comment out that line, everything works fine.

Reproduction repo: https://github.com/adbutterfield/jest-snapshot-issue

Steps to reproduce:

Note: in the reproduction repo, the name for the animation is different when you run test:build, but I actually don't get the issue in my other repo (my actual component library repo).

If you run npm run test:build -- -u it will update the snapshot and you can see the diff in git. It will only be the animation name in the diff, and not everything that jest says is different between the snapshots.