forked from NVIDIA/NeMo-Agent-Toolkit-UI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
86 lines (75 loc) · 1.85 KB
/
jest.setup.js
File metadata and controls
86 lines (75 loc) · 1.85 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
import '@testing-library/jest-dom'
import 'whatwg-fetch'
// Mock IntersectionObserver
global.IntersectionObserver = class IntersectionObserver {
constructor() {}
disconnect() {}
observe() {}
unobserve() {}
}
// Mock ResizeObserver
global.ResizeObserver = class ResizeObserver {
constructor() {}
disconnect() {}
observe() {}
unobserve() {}
}
// Mock window.matchMedia
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
})
// Mock window.scrollTo
Object.defineProperty(window, 'scrollTo', {
writable: true,
value: jest.fn(),
})
// Mock sessionStorage
const localStorageMock = {
getItem: jest.fn(),
setItem: jest.fn(),
removeItem: jest.fn(),
clear: jest.fn(),
}
Object.defineProperty(window, 'sessionStorage', {
value: localStorageMock
})
Object.defineProperty(window, 'localStorage', {
value: localStorageMock
})
// Mock window.open for OAuth testing
Object.defineProperty(window, 'open', {
writable: true,
value: jest.fn(() => ({
close: jest.fn(),
closed: false,
})),
})
// Mock TextEncoder and TextDecoder for Edge runtime compatibility
global.TextEncoder = class TextEncoder {
encode(string) {
return new Uint8Array(Buffer.from(string, 'utf8'));
}
};
global.TextDecoder = class TextDecoder {
decode(bytes, options = {}) {
return Buffer.from(bytes).toString('utf8');
}
};
// Reset all mocks before each test
beforeEach(() => {
jest.clearAllMocks()
localStorageMock.getItem.mockClear()
localStorageMock.setItem.mockClear()
localStorageMock.removeItem.mockClear()
localStorageMock.clear.mockClear()
})