-
Notifications
You must be signed in to change notification settings - Fork 1
/
jest.setup.js
65 lines (54 loc) · 1.94 KB
/
jest.setup.js
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
60
61
62
63
64
65
// Optional: configure or set up a testing framework before each test.
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js`
// Used for __tests__/testing-library.js
// Learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom/extend-expect";
import { faker } from "@faker-js/faker";
import { setConfig } from "next/config";
// @ts-ignore
import { publicRuntimeConfig } from "./next.config";
import { Settings } from "luxon";
Settings.defaultLocale = "en";
Settings.defaultZone = "Europe/Brussels";
Settings.now = jest.fn().mockImplementation(() => Date.now());
// Make sure you can use "publicRuntimeConfig" within tests.
setConfig({
publicRuntimeConfig: {
...publicRuntimeConfig,
GRAPHQL_ENDPOINT: "http://localhost:3000/graphql/",
},
});
// Set seed for faker
faker.seed(1);
// Mock browser confirm
window.confirm = jest.fn();
jest.mock("react-i18next", () => ({
__esModule: true,
I18nextProvider: jest.fn(),
useTranslation: () => ({ t: (key) => key }),
}));
jest.mock("next/router", () => require("next-router-mock"));
// This is needed for mocking 'next/link':
jest.mock("next/dist/client/router", () => require("next-router-mock"));
// https://github.com/scottrippey/next-router-mock/issues/58#issuecomment-1182861712
// Fixes the navigation using links
jest.mock("next/dist/shared/lib/router-context", () => {
const { createContext } = require("react");
const router = require("next-router-mock").default;
const RouterContext = createContext(router);
return { RouterContext };
});
// Mock the IntersectionObserver
const intersectionObserverMock = () => ({
observe: () => null,
unobserve: () => null,
disconnect: () => null,
});
window.IntersectionObserver = jest
.fn()
.mockImplementation(intersectionObserverMock);
// Mock @headlessui/react to disable animations
jest.mock("@headlessui/react", () => ({
__esModule: true,
...jest.requireActual("@headlessui/react"),
}));