question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jest snapshot className issues

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Eventually this is related to #9433 , but i’m not sure.

Expected Behavior

Snapshots should succeed when nothing was changed.

Current Behavior

Whenever introducing a new withStyles() Component or simply updating material-ui to the latest beta our jest test fails due to things like:

-          className="MuiTypography-root-104 MuiTypography-body1-113"
+          className="MuiTypography-root-111 MuiTypography-body1-120"
// or
-        className="MuiExpansionPanelSummary-content-169"
+        className="MuiExpansionPanelSummary-content-176"

basically the appended number changes.

Steps to Reproduce (for bugs)

Sorry I think there is no easy sandbox reproduction possible.

Context

We switched to material-ui from our existing global-css/deterministic className solution where we were able to easily snapshot components and check if they were altered. Now it seems like we have to adjust our setup, but I don’t now how.

Your Environment

Tech Version
Material-UI basically all the v1 beta branches since we started using it (~8+)
React 16

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:16
  • Comments:38 (18 by maintainers)

github_iconTop GitHub Comments

33reactions
oldwincommented, Feb 24, 2018

For Storybook snapshots I use next thing:

.storybook/config.js

import React from 'react';
import JssProvider from 'react-jss/lib/JssProvider';

const generateClassName = (rule, styleSheet) =>
  `${styleSheet.options.classNamePrefix}-${rule.key}`;

addDecorator(story => (
   <JssProvider generateClassName={generateClassName}>
      {story()}
   </JssProvider>
));

...

As result I got the same class names but without counter suffix default

Does anything wrong?

14reactions
denyocommented, Sep 11, 2019

Comments and snippets in this issue refer to JssProvider. The same works with material’s StylesProvider like

const generateClassName = (rule, styleSheet) => `${styleSheet.options.classNamePrefix}-${rule.key}`;

<StylesProvider generateClassName={generateClassName}>
    <ThemeProvider theme={theme}>
        <Component />
    </ThemeProvider>
</StylesProvider>
Read more comments on GitHub >

github_iconTop Results From Across the Web

jest snapshot className issues #9492 - mui/material-ui
Snapshots should succeed when nothing was changed. Current Behavior. Whenever introducing a new withStyles() Component or simply updating ...
Read more >
Issues with snapshot testing in Jest with material-ui
Since I've upgraded to v4 of Material UI, I'm having an issue with my classnames on snapshot testing. Meaning, the classnames are either...
Read more >
Tech Poppy: Challenges with Snapshot Testing in Styled ...
We can see that the dynamic class name has changed, but what about the component's styling? There is no information about the color...
Read more >
Snapshot Testing - Jest
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.
Read more >
React Snapshot Testing: The Bad Parts | by Nick Gard - Medium
Do you have failing snapshot tests? No problem. Run jest --update-snapshots and now they're passing. Your colleagues may scream at you for not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found