Merge branch 'renovate/all-minor-patch' into 'main'
[ProtonMail-WebClient.git] / packages / testing / lib / mockUseLocation.ts
blob76f4b436ccc48a2b5af0a0cfcb6ab3f59334d31a
1 import * as reactRouterDomModule from 'react-router-dom';
3 // A simple workaround for jest issue not solved yet
4 // https://stackoverflow.com/questions/67872622/jest-spyon-not-working-on-index-file-cannot-redefine-property
5 jest.mock('react-router-dom', () => {
6     return {
7         __esModule: true,
8         ...jest.requireActual('react-router-dom'),
9     };
10 });
12 export const mockUseLocation = (value?: Partial<ReturnType<typeof reactRouterDomModule.useLocation>>) => {
13     const mockedUseLocation = jest.spyOn(reactRouterDomModule, 'useLocation');
15     mockedUseLocation.mockReturnValue({
16         pathname: '/',
17         search: '',
18         state: {},
19         hash: '',
20         ...value,
21     });
23     return mockedUseLocation;