-
Notifications
You must be signed in to change notification settings - Fork 2
/
jest.setup.js
78 lines (67 loc) · 1.95 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
66
67
68
69
70
71
72
73
74
75
76
77
78
import { TextEncoder, TextDecoder } from "node:util";
import { jest } from "@jest/globals";
import "@testing-library/jest-dom";
import "whatwg-fetch";
import bugsnag from "@bugsnag/js";
// TextEncoder and TextDecoder are Web APIs but not available in JSDOM
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
// JSDOM does not implement SubmitEvent
global.SubmitEvent =
global.SubmitEvent ||
class MockSubmitEvent extends Event {
constructor(name, options) {
super(name, options);
this.submitter = options?.submitter ?? null;
}
};
jest.mock("react", () => ({
...jest.requireActual("react"),
useId: () => "react-use-id-test-result",
}));
jest.mock("next/dist/client/router", () => require("next-router-mock"));
jest.mock("@bugsnag/js", () => ({
__esModule: true,
default: {
notify: jest.fn(),
start: jest.fn(),
startSession: jest.fn(),
getPlugin: bugsnag.getPlugin,
},
use(plugin) {
const boundary = plugin.init();
// we don't want the error boundary to swallow the errors, we want jest see them and fail the test
delete boundary.prototype.componentDidCatch;
return boundary;
},
}));
jest.mock("./src/node-lib/curriculum-api-2023", () =>
jest.requireActual("./src/node-lib/curriculum-api-2023/__mocks__"),
);
jest.mock("posthog-js", () => ({
__esModule: true,
default: {
init: jest.fn(),
capture: jest.fn(),
onFeatureFlags: jest.fn(),
isFeatureEnabled: jest.fn(),
},
}));
jest.mock("@mux/mux-player-react/lazy", () => ({
__esModule: true,
// noop component
default: () => null,
}));
jest.mock("./src/image-data/generated/inline-sprite.svg", () => "svg");
jest.mock("./src/common-lib/error-reporter", () => ({
__esModule: true,
default: () => () => null,
initialiseBugsnag: jest.fn(),
}));
jest.mock("@oaknational/oak-consent-client");
jest.mock("@clerk/nextjs");
jest.mock("nanoid", () => {
return {
nanoid: (len) => Array(len).fill("x").join(""),
};
});