Skip to content

Instantly share code, notes, and snippets.

@LauraBeatris
Created April 6, 2020 15:29
Show Gist options
  • Save LauraBeatris/f43cda835ab3668084ec235fe66f0a56 to your computer and use it in GitHub Desktop.
Save LauraBeatris/f43cda835ab3668084ec235fe66f0a56 to your computer and use it in GitHub Desktop.
Wrapper of the render method of React Testing Library with Providers
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