Merge branch 'INDA-330-pii-update' into 'main'
[ProtonMail-WebClient.git] / packages / testing / lib / mockUseHistory.ts
blob313238df15dad5716110c568ca8515acc3bfe342
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 mockUseHistory = (value?: Partial<ReturnType<typeof reactRouterDomModule.useHistory>>) => {
13     const mockedUseHistory = jest.spyOn(reactRouterDomModule, 'useHistory');
15     mockedUseHistory.mockReturnValue({
16         length: 0,
17         action: 'PUSH',
18         location: {
19             pathname: '/',
20             search: '',
21             state: {},
22             hash: '',
23         },
24         push: jest.fn(),
25         replace: jest.fn(),
26         go: jest.fn(),
27         goBack: jest.fn(),
28         goForward: jest.fn(),
29         block: jest.fn(),
30         listen: jest.fn(),
31         createHref: jest.fn(),
32         ...value,
33     });
35     return mockedUseHistory;