-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
67 lines (56 loc) · 1.73 KB
/
Copy pathjest.setup.js
File metadata and controls
67 lines (56 loc) · 1.73 KB
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
/* eslint-disable no-undef */
import "@testing-library/jest-dom"
// The scrollIntoView function is necessary for the Tabs component.
window.HTMLElement.prototype.scrollIntoView = jest.fn()
//Set up jose to mock auth for every page test
jest.mock("jose", () => ({
importSPKI: async () => Promise.resolve("testPublicKey"),
jwtVerify: async () => ({
payload: {},
}),
}))
// We expect an error to be thrown and we do catch, but it still gets
// logged and we don't want to see expected errors while we test.
jest.spyOn(global.console, "error").mockImplementation(() => jest.fn())
jest.spyOn(global.console, "warn").mockImplementation(() => jest.fn())
// Increase timeout on tests
jest.setTimeout(40000)
const mockPatronJwtDecodedObj = {
iss: "",
sub: "123",
aud: "",
iat: 123,
exp: 123,
auth_time: 123,
scope: "openid",
}
// Mock the "jose" library that does the JWT verification.
jest.mock("jose", () => ({
importSPKI: async () => Promise.resolve("testPublicKey"),
jwtVerify: async () => ({
payload: mockPatronJwtDecodedObj,
}),
}))
// Mock logger
jest.mock("@nypl/node-utils", () => {
const mockLogger = {
info: jest.fn(),
warning: jest.fn(),
error: jest.fn(),
debug: jest.fn(),
initialize: jest.fn(),
}
const mockConfig = {
loadConfig: jest.fn().mockResolvedValue({ LOG_LEVEL: "debug" }),
getConfig: jest.fn().mockReturnValue({ LOG_LEVEL: "debug" }),
}
return {
logger: mockLogger,
config: mockConfig,
}
})
// Related to the useNYPLBreakpoints hook which is used in: ButtonGroup,
// FeedbackBox, Modal, MultiSelectGroup, and NewsletterSignup.
import { MatchMedia } from "@nypl/design-system-react-components"
new MatchMedia()
window.HTMLElement.prototype.scrollIntoView = jest.fn()