Skip to content

Snapshotting logic does not provide an adequate className in a testing environment. #14357

Description

@jesusmaldonado
  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

This was a previously #9492 however it does not actually provide a fix for the core problem which is that in testing environments we should be able to mount(<Component>) that are created from withStyles() and have snapshots be reliable without wrapping them.

Expected Behavior 🤔

Snapshots should create reliable labels for withStyles() used by both custom and defaut material-ui components like in the red portion of this Snapshot:
screen shot 2019-01-30 at 5 29 11 pm

Current Behavior 😯

One can modify a custom component to have

withStyles(Styles, { generateClassName: (rule, styleSheet) => (`${styleSheet.options.classNamePrefix}-${rule.key}`)  
})

However, this only modifies overwritten styles in material UI, default ones are actually not modified at all:

screen shot 2019-01-30 at 5 23 10 pm

## Steps to Reproduce 🕹 This can't be easily reproduced in a sandbox environment. Link:
  1. Make a withStyles() that uses MUI components as well
  2. Install a testing framework like jest
  3. Run snapshots
  4. Add a new test, and you will see how the snapshots will fail on prior ones because the ruleCounter increases.

Context 🔦

I would like to be able to mount() and call Jest's native .toMatchSnapshot() without worrying about the ruleCounter adding random numbers. It is not appropriate to wrap every object in a as stated in the docs of https://material-ui.com/customization/css-in-js/#creategenerateclassname-options-class-name-generator because tests should mirror their native implementation.

Your Environment 🌎

Ma

Tech Version
Material-UI v3.9.1
React 16.5.2
Browser
TypeScript
etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements or additions to the documentation.testv4.x

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions