mirror of
https://git.unlock-music.dev/um/um-react.git
synced 2024-11-24 06:12:16 +00:00
26 lines
876 B
TypeScript
26 lines
876 B
TypeScript
|
import { PreloadedState } from '@reduxjs/toolkit';
|
||
|
import { RenderOptions, render } from '@testing-library/react';
|
||
|
import { PropsWithChildren } from 'react';
|
||
|
import { Provider } from 'react-redux';
|
||
|
import { AppStore, RootState, setupStore } from '~/store';
|
||
|
|
||
|
// Adapted from: https://redux.js.org/usage/writing-tests
|
||
|
|
||
|
export * from '@testing-library/react';
|
||
|
|
||
|
export interface ExtendedRenderOptions extends RenderOptions {
|
||
|
preloadedState?: PreloadedState<RootState>;
|
||
|
store?: AppStore;
|
||
|
}
|
||
|
|
||
|
export function renderWithProviders(
|
||
|
ui: React.ReactElement,
|
||
|
{ preloadedState = {}, store = setupStore(preloadedState), ...renderOptions }: ExtendedRenderOptions = {}
|
||
|
) {
|
||
|
function Wrapper({ children }: PropsWithChildren<{}>): JSX.Element {
|
||
|
return <Provider store={store}>{children}</Provider>;
|
||
|
}
|
||
|
|
||
|
return { store, ...render(ui, { wrapper: Wrapper, ...renderOptions }) };
|
||
|
}
|