-
-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jest snapshots different classnames #595
Comments
This looks related to #562 |
This isn't a fix, but it might help someone out. We're using react-tooltip in a Storybook.js component library, and it was failing tests for the reason reported. For now, I've just had to ignore the stories that use this component from Storybook's testing suite.
I imagine Jest natively has a similar 'ignore' config value - I'm not familiar with it beyond Storybook's Storyshot addon. Not ideal, but it does mean we can move past this. |
What version did this appear? |
This first started to occur with version jest.mock("uuid", () => ({ v4: () => "00000000-0000-0000-0000-000000000000" })); Initially The current implementation has certain limitations. For example, if your package (or a dependency) depends on a non-compatible jest.mock("react-tooltip/node_modules/uuid", () => ({ v4: () => "00000000-0000-0000-0000-000000000000" })); This could be fixed by making Another alternative that does not depend on jest.mock('crypto', () => ({ randomBytes: (num) => new Array(num).fill(0) })); However, this approach can potentially break other testing that depend on the core As you can see, no solution is without its hiccups, and besides, none of these approaches are officially documented. I believe a more robust approach would be to expose a static method or property that could be executed so that generated uuids are static. For example: // jest setup file
import ReactTooltip from "react-tooltip";
// alt names: .enableSnapshotMode(), .enableTestMode(), .testMode(), .snapshotMode()
ReactTooltip.useStaticUuids(); |
We just started using react-tooltip today and it also breaks our snapshot tests... Any update on this? |
@marcogrcr Thank you for the initial ideas. I've found a workaround for the jest.mock(
(() => {
// This will mock the version of uuid belonging to react-tooltip
// if it exists, otherwise use the top-level uuid module
try {
require('react-tooltip/node_modules/uuid');
return 'react-tooltip/node_modules/uuid';
} catch (error) {
return 'uuid';
}
})(),
() => ({
v4: () => '00000000-0000-0000-0000-000000000000',
})
); That should make the tests a bit more reliable across dependency and react-tooltip updates. |
Everytime i run snapshot test with jest and rest-testing-library for component with tooltip inside, new css classes are generated and thus snapshot is failing. Any ideas to solve this ?
The text was updated successfully, but these errors were encountered: