-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.setup.js
More file actions
52 lines (44 loc) · 1.19 KB
/
Copy pathvitest.setup.js
File metadata and controls
52 lines (44 loc) · 1.19 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
import { vi, beforeEach } from 'vitest';
// Load the config module
import CONFIG from './src/core/config.js';
// Polyfill innerText for jsdom (it doesn't implement innerText)
if (!('innerText' in Element.prototype)) {
Object.defineProperty(Element.prototype, 'innerText', {
get() {
return this.textContent;
},
set(value) {
this.textContent = value;
}
});
}
// Setup browser globals
beforeEach(() => {
// Reset document
document.body.innerHTML = '';
document.head.innerHTML = '';
// Make CONFIG available on window
window.DETECTOR_CONFIG = CONFIG;
// Mock fetch
global.fetch = vi.fn();
// Mock PerformanceObserver
global.PerformanceObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
disconnect: vi.fn(),
takeRecords: vi.fn(() => [])
}));
// Mock performance.getEntriesByType
global.performance.getEntriesByType = vi.fn(() => []);
// Mock navigator
Object.defineProperty(global, 'navigator', {
value: {
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Chrome/120.0.0.0',
connection: {
effectiveType: '4g',
downlink: 10,
rtt: 50
}
},
writable: true
});
});