-
Notifications
You must be signed in to change notification settings - Fork 4
/
jest.setup.ts
59 lines (53 loc) · 1.76 KB
/
jest.setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import isBetween from 'dayjs/plugin/isBetween';
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
import isoWeek from 'dayjs/plugin/isoWeek';
import minMax from 'dayjs/plugin/minMax';
import relativeTime from 'dayjs/plugin/relativeTime';
import * as mockRouter from 'next-router-mock';
import { createDynamicRouteParser } from 'next-router-mock/dynamic-routes';
dayjs.extend(relativeTime);
dayjs.extend(minMax);
dayjs.extend(isBetween);
dayjs.extend(isSameOrAfter);
dayjs.extend(isSameOrBefore);
dayjs.extend(isoWeek);
dayjs.extend(customParseFormat);
dayjs.locale('nb');
require('jest-axe/extend-expect');
require('@testing-library/jest-dom');
mockRouter.default.useParser(
createDynamicRouteParser([
'/',
'/person/[aktorId]/dagoversikt',
'/person/[aktorId]/inngangsvilkår',
'/person/[aktorId]/sykepengegrunnlag',
'/person/[aktorId]/vurderingsmomenter',
'/person/[aktorId]/tilkommen-inntekt',
]),
);
const useRouter = mockRouter.useRouter;
export const MockNextNavigation = {
...mockRouter,
notFound: jest.fn(),
redirect: jest.fn().mockImplementation((url: string) => {
mockRouter.memoryRouter.setCurrentUrl(url);
}),
usePathname: () => {
const router = useRouter();
return router.asPath;
},
useSearchParams: () => {
const router = useRouter();
const path = router.query;
return new URLSearchParams(path as never);
},
useParams: () => {
const router = useRouter();
const path = router.query;
return path as never;
},
};
jest.mock('next/navigation', () => MockNextNavigation);