/
dedaMazai
/
TestServer
Обзор
Документация
Войти
/
dedaMazai
/
TestServer
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/shared/lib/tests/componentRender/componentRender.tsx
56 строк
2 KB
Andrey Chipizubov
fix
23 апр 2023, 17:32
23 апр 2023, 17:32
cc424e9
Код
Авторство
О чём код?
import { ReactNode } from 'react'; import { render } from '@testing-library/react'; import { I18nextProvider } from 'react-i18next'; import { MemoryRouter } from 'react-router-dom'; import { ReducersMapObject } from '@reduxjs/toolkit'; import i18nForTests from '@/shared/config/i18n/i18nForTests'; import { StateSchema, StoreProvider } from '@/app/providers/StoreProvider'; import { Theme } from '@/shared/const/theme'; // eslint-disable-next-line ulbi-tv-plugin/layer-imports import { ThemeProvider } from '@/app/providers/ThemeProvider'; // eslint-disable-next-line ulbi-tv-plugin/layer-imports import '@/app/styles/index.scss'; export interface componentRenderOptions { route?: string; initialState?: DeepPartial<StateSchema>; asyncReducers?: DeepPartial<ReducersMapObject<StateSchema>>; theme?: Theme; } interface TestProviderProps { children: ReactNode; options?: componentRenderOptions; } export function TestProvider(props: TestProviderProps) { const { children, options = {} } = props; const { route = '/', initialState, asyncReducers, theme = Theme.LIGHT, } = options; return ( <MemoryRouter initialEntries={[route]}> <StoreProvider asyncReducers={asyncReducers} initialState={initialState} > <I18nextProvider i18n={i18nForTests}> <ThemeProvider initialTheme={theme}> <div className={`app ${theme}`}>{children}</div> </ThemeProvider> </I18nextProvider> </StoreProvider> </MemoryRouter> ); } export function componentRender( component: ReactNode, options: componentRenderOptions = {}, ) { return render(<TestProvider options={options}>{component}</TestProvider>); }