-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
39 lines (33 loc) · 977 Bytes
/
vitest.setup.ts
File metadata and controls
39 lines (33 loc) · 977 Bytes
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
import { expect, afterEach, vi, beforeAll } from 'vitest';
import { cleanup } from '@testing-library/react';
import * as matchers from '@testing-library/jest-dom/matchers';
expect.extend(matchers);
// Setup localStorage mock with actual storage
beforeAll(() => {
const store: Record<string, string> = {};
const localStorageMock = {
getItem: (key: string) => store[key] || null,
setItem: (key: string, value: string) => {
store[key] = value.toString();
},
removeItem: (key: string) => {
delete store[key];
},
clear: () => {
Object.keys(store).forEach(key => delete store[key]);
},
};
global.localStorage = localStorageMock as any;
});
afterEach(() => {
cleanup();
vi.clearAllMocks();
if (global.localStorage) {
global.localStorage.clear();
}
});
// Mock ws module to prevent WebSocket import errors from ethers
vi.mock('ws', () => ({
default: class WebSocket {},
WebSocket: class WebSocket {},
}));