-
Notifications
You must be signed in to change notification settings - Fork 54
/
test-utils.tsx
29 lines (24 loc) · 1.04 KB
/
test-utils.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { defaultTheme } from '@medly-components/theme';
import { render, RenderOptions, RenderResult } from '@testing-library/react';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import type { FC, ReactElement } from 'react';
import { ThemeProvider } from 'styled-components';
import { SWRConfig } from 'swr';
export const mockAxios = new MockAdapter(axios);
const WithTheme: FC = props => (
<ThemeProvider theme={defaultTheme}>
<>{props.children}</>
</ThemeProvider>
);
const WithSWR: FC = props => (
<SWRConfig value={{ provider: () => new Map() }}>
<>{props.children}</>
</SWRConfig>
);
const customRender = (ui: ReactElement<any>, options?: RenderOptions): RenderResult => render(ui, { wrapper: WithTheme, ...options });
const renderWithSWR = (ui: ReactElement<any>, options?: RenderOptions): RenderResult => render(ui, { wrapper: WithSWR, ...options });
// re-export everything
export * from '@testing-library/react';
// override render method
export { customRender as render, renderWithSWR };