-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
72 lines (60 loc) · 1.29 KB
/
Copy pathjest.setup.js
File metadata and controls
72 lines (60 loc) · 1.29 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
import '@testing-library/jest-dom';
import { jest } from '@jest/globals';
import { TextEncoder, TextDecoder } from 'util';
class LocalStorageMock {
constructor() {
this.store = {};
}
clear() {
this.store = {};
}
getItem(key) {
return this.store[key] || null;
}
setItem(key, value) {
this.store[key] = String(value);
}
removeItem(key) {
delete this.store[key];
}
}
// Mock fetch
global.fetch = jest.fn(() =>
Promise.resolve({
ok: true,
json: () => Promise.resolve({}),
})
);
// Define global objects for the test environment
Object.defineProperty(global, 'localStorage', {
value: new LocalStorageMock(),
});
Object.defineProperty(global, 'sessionStorage', {
value: new LocalStorageMock(),
});
// Mock window.location
delete window.location;
window.location = {
pathname: '/',
search: '',
hash: '',
href: 'http://localhost/',
assign: jest.fn(),
replace: jest.fn(),
};
// Mock Intersection Observer
global.IntersectionObserver = class IntersectionObserver {
constructor() {}
disconnect() {}
observe() {}
unobserve() {}
};
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
// Mock ResizeObserver
global.ResizeObserver = class ResizeObserver {
constructor() {}
disconnect() {}
observe() {}
unobserve() {}
};