-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
38 lines (33 loc) · 1.3 KB
/
vitest.setup.ts
File metadata and controls
38 lines (33 loc) · 1.3 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
import '@testing-library/jest-dom';
import { beforeAll, vi } from 'vitest';
// Suppress console warnings during tests to keep output clean
beforeAll(() => {
const originalWarn = console.warn;
vi.spyOn(console, 'warn').mockImplementation((...args) => {
// Only suppress expected parser warnings, let others through
const message = args[0]?.toString() || '';
if (message.includes('Failed to parse') || message.includes('Validation error')) {
return;
}
originalWarn(...args);
});
// Mock DOM dimensions for ECharts (jsdom doesn't compute actual dimensions)
// This fixes "Can't get DOM width or height" warnings in tests
Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
configurable: true,
value: 800,
});
Object.defineProperty(HTMLElement.prototype, 'clientHeight', {
configurable: true,
value: 600,
});
// Mock ResizeObserver for ECharts and echarts-for-react
// This fixes "Cannot read properties of undefined (reading 'disconnect')" errors
// Using regular function constructor (not arrow function) for proper instantiation
const ResizeObserverMock = vi.fn(function (this: ResizeObserver) {
this.observe = vi.fn();
this.unobserve = vi.fn();
this.disconnect = vi.fn();
});
vi.stubGlobal('ResizeObserver', ResizeObserverMock);
});