Skip to content

Instantly share code, notes, and snippets.

@fatso83
Created August 2, 2019 08:05
Show Gist options
  • Save fatso83/00d64d6273eef1f2edabae97701d045d to your computer and use it in GitHub Desktop.
Save fatso83/00d64d6273eef1f2edabae97701d045d to your computer and use it in GitHub Desktop.
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