-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-setup.js
More file actions
45 lines (38 loc) · 995 Bytes
/
Copy pathtest-setup.js
File metadata and controls
45 lines (38 loc) · 995 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
40
41
42
43
44
45
import { vi } from 'vitest';
// Mock browser APIs that might not be available in jsdom
global.fetch = vi.fn();
// Mock navigator.onLine
Object.defineProperty(navigator, 'onLine', {
writable: true,
value: true
});
// Mock window events
global.window = global.window || {};
global.window.addEventListener = vi.fn();
global.window.removeEventListener = vi.fn();
global.window.dispatchEvent = vi.fn();
// Mock console methods to avoid noise in tests
global.console = {
...console,
log: vi.fn(),
warn: vi.fn(),
error: vi.fn()
};
// Setup default fetch mock responses
beforeEach(() => {
// Reset all mocks before each test
vi.clearAllMocks();
// Default successful fetch response
global.fetch.mockResolvedValue({
ok: true,
json: () => Promise.resolve({
utc_datetime: new Date().toISOString(),
timezone: 'UTC'
})
});
// Reset navigator.onLine to true
Object.defineProperty(navigator, 'onLine', {
writable: true,
value: true
});
});