1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/frontend/src/utils/testRenderer.tsx
olav d8143c6ff4 chore: update react-router to v6 (#946)
* refactor: fix child selector warnings

* refactor: update react-router-dom

* refactor: use BrowserRouter as in react-router docs

* refactor: replace Redirect with Navigate

* refactor: replace Switch with Routes

* refactor: replace useHistory with useNavigate

* refactor: replace useParams types with useRequiredPathParam

* refactor: replace NavLink activeStyle with callback

* refactor: fix matchPath arg order

* refactor: Remove unused link state

* refactor: delete broken snapshot test

* refactor: render 404 page without redirect

* refactor: normalize path parameter names

* refactor: fix Route component usage
2022-05-05 13:42:18 +02:00

40 lines
1.3 KiB
TypeScript

import React, { FC } from 'react';
import { BrowserRouter } from 'react-router-dom';
import { render as rtlRender, RenderOptions } from '@testing-library/react';
import { SWRConfig } from 'swr';
import { ThemeProvider } from 'themes/ThemeProvider';
import { IPermission } from 'interfaces/user';
import { AnnouncerProvider } from 'component/common/Announcer/AnnouncerProvider/AnnouncerProvider';
import { AccessProviderMock } from 'component/providers/AccessProvider/AccessProviderMock';
export const render = (
ui: JSX.Element,
{
route = '/',
permissions = [],
...renderOptions
}: { route?: string; permissions?: IPermission[] } & Omit<
RenderOptions,
'queries'
> = {}
) => {
window.history.pushState({}, 'Test page', route);
const Wrapper: FC = ({ children }) => (
<SWRConfig value={{ provider: () => new Map() }}>
<AccessProviderMock permissions={permissions}>
<ThemeProvider>
<AnnouncerProvider>
<BrowserRouter>{children}</BrowserRouter>
</AnnouncerProvider>
</ThemeProvider>
</AccessProviderMock>
</SWRConfig>
);
return rtlRender(ui, {
wrapper: Wrapper,
...renderOptions,
});
};