-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjest.setup.js
54 lines (47 loc) · 1.21 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
/* eslint-disable @typescript-eslint/no-empty-function */
// 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";
// setup jest-fetch-mock
import { enableFetchMocks } from "jest-fetch-mock";
enableFetchMocks();
jest.mock("next/dynamic", () => ({
__esModule: true,
default: () => null,
}));
jest.mock("next/router", () => ({
useRouter() {
return {
asPath: "/",
events: {
off: jest.fn(),
on: jest.fn(),
},
pathname: "/",
query: "",
route: "/",
};
},
}));
/** * fix: `matchMedia` not present, legacy browsers require a polyfill */
global.matchMedia =
global.matchMedia ||
function () {
return {
addListener () {},
matches: false,
removeListener () {},
};
};
const observe = jest.fn();
const unobserve = jest.fn();
const disconnect = jest.fn();
// you can also pass the mock implementation
// to jest.fn as an argument
global.IntersectionObserver = jest.fn(() => ({
disconnect,
observe,
unobserve,
}));