React-tooltip: Generated UUID in 4.0.5 breaks snapshot testing

Created on 11 Mar 2020  Â·  9Comments  Â·  Source: wwayne/react-tooltip

This commit https://github.com/wwayne/react-tooltip/commit/78e3c2be784f2b96d8bb888b81785b2b38179dae added generateUUID, which generates a random UUID every time a tooltip is rendered, which changes Jest snapshots every time they're run.

That commit was done in https://github.com/wwayne/react-tooltip/pull/559, which says "No changes in workflows or documentation", which, while true, apparently didn't take into account changes in the DOM and testing. I would recommend a solution without the uuid state, if possible, but if not, some override that would disable the UUID in testing

Most helpful comment

So it's not nice but it works:

jest.mock('crypto', () => ({
  randomBytes: (num: number) => new Array(num).fill(0),
}));

With this my classNames look like:

__react_component_tooltip t00000000-0000-4000-8000-000000000000

All 9 comments

It's better to use v4 from npm module uuid to implement generateUUID. Module "uuid" may be mocked in jest for testing. But it's impossible to mock function that is not exported from your module.

@Rogger794 Are there any plans to fix this in an upcoming release?

Sounds like we have a proposed fix. We would be happy to accept a PR to fix
it.

On Fri, Mar 20, 2020 at 9:27 AM Steven Rathbauer notifications@github.com
wrote:

@Rogger794 https://github.com/Rogger794 Are there any plans to fix this
in an upcoming release?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/wwayne/react-tooltip/issues/562#issuecomment-601700128,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEX6THN4AY3OHQ7I7BNPG73RINVNBANCNFSM4LF7AXMQ
.

:tada: This issue has been resolved in version 4.1.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Hi, I'm afraid the issue still stands. The uuid get's bundled together with rest of the code in /dist/index.js, which makes it unmockable.

it would be nice if you could just optionally send a flag through the component to override the class. I think this would resolve the problem for snapshots

So it's not nice but it works:

jest.mock('crypto', () => ({
  randomBytes: (num: number) => new Array(num).fill(0),
}));

With this my classNames look like:

__react_component_tooltip t00000000-0000-4000-8000-000000000000

Could this be an issue with rollup's config? I don't have experience with this tool, but it seems that we should exclude dependencies from our bundle

// rollup.config.js
...
export default {
external: Object.keys(pkg.dependencies || {}),
...

or put uuid inside peerDependecies which then would be automatically excluded via used rollup-plugin-peer-deps-external.

my vote is for excluding dependencies or you could simply just exclude uuid, but since there are only two deps in package it is probably ok to do them all.

the single approach would be this:

external: ['uuid']
Was this page helpful?
0 / 5 - 0 ratings

Related issues

donilan picture donilan  Â·  4Comments

oran1248 picture oran1248  Â·  3Comments

abijames picture abijames  Â·  3Comments

tonynd picture tonynd  Â·  3Comments

kristinadarroch picture kristinadarroch  Â·  3Comments