Skip to content

Instantly share code, notes, and snippets.

@denieler
Created January 10, 2019 19:50
Show Gist options
  • Save denieler/2074867f33275720fb54614b4c96bd10 to your computer and use it in GitHub Desktop.
Save denieler/2074867f33275720fb54614b4c96bd10 to your computer and use it in GitHub Desktop.
Custom render function for react-testing-library for jest snapshots with jss
import React from 'react'
import { render } from 'react-testing-library'
import JssProvider from 'react-jss/lib/JssProvider'
const generateClassName = (rule, styleSheet) =>
`${styleSheet.options.classNamePrefix}-${rule.key}`
const customRender = (node, options) => {
return render(
<JssProvider generateClassName={generateClassName}>
{node}
</JssProvider>,
options
)
}
// re-export everything
export * from 'react-testing-library'
// override render method
export { customRender as render }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment