Created
August 2, 2019 08:05
-
-
Save fatso83/00d64d6273eef1f2edabae97701d045d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {mount as enzymeMount, render as enzymeRender, shallow as enzymeShallow} from 'enzyme'; | |
import React from 'react'; | |
import JssProvider from 'react-jss/lib/JssProvider'; | |
export const generateClassName = (rule, styleSheet) => `${styleSheet.options.classNamePrefix}-${rule.key}`; | |
function consistentClassNameWrapper(func, overrides = {}) { | |
return function(children, ...opts) { | |
let wrapper = func(<JssProvider generateClassName={generateClassName}>{children}</JssProvider>, ...opts); | |
for (const key in overrides) { | |
wrapper[key] = overrides[key]; | |
} | |
return wrapper; | |
}; | |
} | |
/** | |
* Renders the component tree in Enzyme using a custom JssProvider that provides static class names | |
* This way our snapshots are not different just by changing the order of the tests | |
* | |
* @see https://github.com/mui-org/material-ui/issues/9492 | |
*/ | |
export const render = consistentClassNameWrapper(enzymeRender); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment