forked from marumaru1019/PoC-GitHubCopilotApp2-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
65 lines (55 loc) · 1.47 KB
/
vitest.setup.ts
File metadata and controls
65 lines (55 loc) · 1.47 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
import '@testing-library/jest-dom/vitest';
import { afterAll, afterEach, beforeAll, vi } from 'vitest';
import { server } from './mocks/server';
import { resetTicketMocks } from '@/mocks/handlers/tickets';
beforeAll(() => {
server.listen({ onUnhandledRequest: 'error' });
});
afterEach(() => {
server.resetHandlers();
resetTicketMocks();
vi.clearAllMocks();
});
afterAll(() => {
server.close();
});
const createStorage = () => {
let store: Record<string, string> = {};
return {
getItem: (key: string) => (key in store ? store[key] : null),
setItem: (key: string, value: string) => {
store[key] = value;
},
removeItem: (key: string) => {
delete store[key];
},
clear: () => {
store = {};
},
};
};
Object.defineProperty(global, 'localStorage', {
value: createStorage(),
configurable: true,
});
Object.defineProperty(global, 'sessionStorage', {
value: createStorage(),
configurable: true,
});
class MockIntersectionObserver implements IntersectionObserver {
readonly root: Element | null = null;
readonly rootMargin = '0px';
readonly thresholds = [] as ReadonlyArray<number>;
constructor(private readonly callback: IntersectionObserverCallback) {}
observe(): void {}
unobserve(): void {}
disconnect(): void {}
takeRecords(): IntersectionObserverEntry[] {
return [];
}
}
Object.defineProperty(global, 'IntersectionObserver', {
writable: true,
configurable: true,
value: MockIntersectionObserver,
});