-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.render.tsx
52 lines (46 loc) · 1.63 KB
/
test.render.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from 'react';
import { configureStore } from '@reduxjs/toolkit';
import { render as defaultRender, RenderResult } from '@testing-library/react';
import { RouterContext } from 'next/dist/shared/lib/router-context';
import { NextRouter } from 'next/router';
import { Provider } from 'react-redux';
import { ThemeProvider } from 'styled-components';
import { mockRouter } from './__mocks__/NextRouter';
import { reducer } from './src/store';
import { GlobalStyle } from './src/styles/global';
type DefaultParams = Parameters<typeof defaultRender>;
type RenderUI = DefaultParams[0];
type RenderOptions = DefaultParams[1] & { router?: Partial<NextRouter> };
const customRender = (
ui: RenderUI,
{
preloadedState = {},
store = configureStore({
reducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware()
.concat
// api middleware
(),
preloadedState,
}),
...renderOptions
} = {},
{ router }: RenderOptions = {}
): RenderResult => {
const Providers = ({ children }) => (
<Provider store={store}>
<ThemeProvider theme={{}}>
<RouterContext.Provider value={{ ...mockRouter, ...router }}>
<GlobalStyle />
{children}
</RouterContext.Provider>
</ThemeProvider>
</Provider>
);
return defaultRender(ui, { wrapper: Providers, ...renderOptions });
};
// re-export everything
export * from '@testing-library/react';
// override render method
export { customRender as render };