blob: 476fdb1e9b35a3f00a188ce65ec1fbea3a6a3812 (
plain)
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
|
import React, { PropsWithChildren, ReactElement } from 'react';
import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
import setupStore from './store';
import type { AppStore, RootState } from './store';
import type { RenderOptions } from '@testing-library/react';
interface ExtendedRenderOptions extends Omit<RenderOptions, 'queries'> {
preloadedState?: Partial<RootState>;
store?: AppStore;
}
export function renderWithProviders(
ui: ReactElement,
extendedRenderOptions: ExtendedRenderOptions = {}
) {
const {
preloadedState = {},
store = setupStore(preloadedState),
...renderOptions
} = extendedRenderOptions;
const Wrapper = ({ children }: PropsWithChildren) => (
<Provider store={store}>{children}</Provider>
);
return { store, ...render(ui, { wrapper: Wrapper, ...renderOptions }) };
}
|