gilbarbara/react-inlinesvg

Jest snapshots failing due to unique hash

nialloc9 opened this issue · 8 comments

Jest tests seem to be failing for every test that include react-inlinesvg due to the unique hash not matching. As the hash changes every time the test is run the snapshot does no match. Is there a way of testing this without breaking tests? Attached is an image of the failing snapshot test.

screenshot from 2017-11-27 11-54-33

Yes, using props.
You can turn off hashing with uniquifyIDs or pass your own hash with uniquifyIDs

Thank you for your reply. Yes this was actually what I did earlier today to fix this and I can confirm it will but I was kind of hoping that there might be another solution out there that didn't involve changing the application code to make the tests work. Even though it doesn't effect how the application runs and works perfectly well.

I did update the minor version, that requires you to update it manually.

But I failed to mention the unique hash changes in the 0.7.0 release notes, sorry.

Thats cool. Awesome job by the way.

@gilbarbara this still seems to be adding a uniqueHash prop to my components :( . is it possible it isn't fixed yet?

screen shot 2018-01-31 at 4 43 58 pm

Here is a screenshot to show you jest is still failing even with the prop set to false.

Also as a workaround I'm using enzymes 'shallow' instead of 'mount' to create the snapshot. However, Ideally I'd like to turn mount back on.

Perhaps we can learn something from https://github.com/styled-components/jest-styled-components. Styled components assign random hashes to the elements and this plugin allows jest snapshots to continue to pass.

@mackbrowne fixed in 7f8dd86
published as 0.7.5

@gilbarbara great work. Thank you.

@gilbarbara thanks upgrading to 075 fixed it!