-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
87 lines (76 loc) · 2.29 KB
/
jest.setup.js
File metadata and controls
87 lines (76 loc) · 2.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import "@testing-library/jest-dom";
// Mock blockchain-related modules to prevent ES module issues
jest.mock("wagmi", () => ({
useAccount: jest.fn(() => ({ address: "0x1234567890123456789012345678901234567890" })),
useWriteContract: jest.fn(() => ({ writeContract: jest.fn() })),
useReadContract: jest.fn(() => ({ data: null, isLoading: false })),
useWaitForTransactionReceipt: jest.fn(() => ({ data: null, isLoading: false })),
}));
jest.mock("viem", () => ({
getAddress: jest.fn((address) => address),
parseEther: jest.fn((value) => value),
formatEther: jest.fn((value) => value),
encodePacked: jest.fn((types, values) => "0xencoded"),
keccak256: jest.fn((data) => "0xhash"),
}));
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(() => null),
getDefaultWallets: jest.fn(() => []),
connectorsForWallets: jest.fn(() => []),
}));
// Mock localStorage globally for all tests
const localStorageMock = (() => {
let store = {};
return {
getItem: jest.fn((key) => store[key] || null),
setItem: jest.fn((key, value) => {
store[key] = value.toString();
}),
removeItem: jest.fn((key) => {
delete store[key];
}),
clear: jest.fn(() => {
store = {};
}),
};
})();
Object.defineProperty(window, "localStorage", {
value: localStorageMock,
});
// Add missing global objects for blockchain libraries
if (typeof global.TextEncoder === 'undefined') {
global.TextEncoder = require('util').TextEncoder;
}
if (typeof global.TextDecoder === 'undefined') {
global.TextDecoder = require('util').TextDecoder;
}
// Mock crypto for blockchain libraries
Object.defineProperty(global, "crypto", {
value: {
getRandomValues: (arr) => {
for (let i = 0; i < arr.length; i++) {
arr[i] = Math.floor(Math.random() * 256);
}
return arr;
},
subtle: {
generateKey: jest.fn(),
sign: jest.fn(),
verify: jest.fn(),
},
},
});
// Mock fetch for API calls
global.fetch = jest.fn();
// Mock ResizeObserver
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
// Mock IntersectionObserver
global.IntersectionObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));