-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathjest.setup.ts
More file actions
87 lines (77 loc) · 2.16 KB
/
jest.setup.ts
File metadata and controls
87 lines (77 loc) · 2.16 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import '@testing-library/jest-dom';
import { TextEncoder } from 'node:util';
/**
* Gitify context bridge API
*/
window.gitify = {
app: {
version: jest.fn().mockResolvedValue('v0.0.1'),
hide: jest.fn(),
quit: jest.fn(),
show: jest.fn(),
},
twemojiDirectory: jest.fn().mockResolvedValue('/mock/images/assets'),
openExternalLink: jest.fn(),
decryptValue: jest.fn().mockResolvedValue('decrypted'),
encryptValue: jest.fn().mockResolvedValue('encrypted'),
platform: {
isLinux: jest.fn().mockReturnValue(false),
isMacOS: jest.fn().mockReturnValue(true),
isWindows: jest.fn().mockReturnValue(false),
},
zoom: {
getLevel: jest.fn(),
setLevel: jest.fn(),
},
tray: {
updateIcon: jest.fn(),
updateTitle: jest.fn(),
useAlternateIdleIcon: jest.fn(),
},
notificationSoundPath: jest.fn(),
onAuthCallback: jest.fn(),
onResetApp: jest.fn(),
onSystemThemeUpdate: jest.fn(),
setAutoLaunch: jest.fn(),
setKeyboardShortcut: jest.fn(),
raiseNativeNotification: jest.fn(),
};
// Mock OAuth client ID and secret
process.env.OAUTH_CLIENT_ID = 'FAKE_CLIENT_ID_123';
process.env.OAUTH_CLIENT_SECRET = 'FAKE_CLIENT_SECRET_123';
/**
* Primer (@primer/react) Setup - START
*
* Borrowed from https://github.com/primer/react/blob/main/packages/react/src/utils/test-helpers.tsx
*/
// JSDOM doesn't mock ResizeObserver
global.ResizeObserver = jest.fn().mockImplementation(() => {
return {
observe: jest.fn(),
disconnect: jest.fn(),
unobserve: jest.fn(),
};
});
// @ts-expect-error only declare properties used internally
global.CSS = {
escape: jest.fn(),
supports: jest.fn().mockImplementation(() => {
return false;
}),
};
// @ts-expect-error: prevent ReferenceError: TextEncoder is not defined
global.TextEncoder = TextEncoder;
/**
* Primer (@primer/react) Setup - END
*/
window.HTMLMediaElement.prototype.play = jest.fn();
window.matchMedia = (query: string): MediaQueryList => ({
matches: false,
media: query,
onchange: null,
addListener: () => {}, // deprecated
removeListener: () => {}, // deprecated
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => false,
});