-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathjest.setup.ts
More file actions
62 lines (53 loc) · 1.59 KB
/
Copy pathjest.setup.ts
File metadata and controls
62 lines (53 loc) · 1.59 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
import '@testing-library/jest-dom'
// React 18 concurrent features in tests
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true
// jsdom does not always define Notification; Push API tests need a minimal stub
if (typeof globalThis.Notification === 'undefined') {
type Perm = 'default' | 'denied' | 'granted'
class NotificationStub {
static permission: Perm = 'default'
static requestPermission(): Promise<Perm> {
return Promise.resolve(NotificationStub.permission)
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(globalThis as any).Notification = NotificationStub
}
// Mock ResizeObserver
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}))
// Mock html2canvas
jest.mock('html2canvas', () =>
jest.fn(() =>
Promise.resolve({
toBlob: (callback: Function) => callback(new Blob()),
})
)
)
// Mock TextEncoder for Stellar SDK
global.TextEncoder = require('util').TextEncoder
// Mock TextDecoder for Stellar SDK
global.TextDecoder = require('util').TextDecoder
// Mock localStorage
const localStorageMock = (function () {
let store: Record<string, string> = {}
return {
getItem: (key: string) => store[key] || null,
setItem: (key: string, value: string) => {
store[key] = value.toString()
},
clear: () => {
store = {}
},
removeItem: (key: string) => {
delete store[key]
},
}
})()
Object.defineProperty(window, 'localStorage', {
value: localStorageMock,
})