Created
April 6, 2020 15:29
-
-
Save LauraBeatris/f43cda835ab3668084ec235fe66f0a56 to your computer and use it in GitHub Desktop.
Wrapper of the render method of React Testing Library with Providers
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 React from 'react'; | |
import { render } from '@testing-library/react'; | |
import { ThemeProvider } from 'styled-components'; | |
import { MemoryRouter } from 'react-router-dom'; | |
import theme from '~/styles/theme'; | |
// eslint-disable-next-line | |
function ProvidersWrapper({ children }) { | |
return ( | |
<MemoryRouter> | |
<ThemeProvider theme={theme}>{children}</ThemeProvider> | |
</MemoryRouter> | |
); | |
} | |
function customRender(component, options) { | |
return render(component, { wrapper: ProvidersWrapper, ...options }); | |
} | |
// re-export everything | |
export * from '@testing-library/react'; | |
// 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