-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ts
94 lines (77 loc) · 2.07 KB
/
setup.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import '@testing-library/jest-dom';
import { vi } from 'vitest';
import ResizeObserver from "resize-observer-polyfill"
import 'vitest-canvas-mock'
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
})
global.ResizeObserver = ResizeObserver
Object.defineProperty(global.SVGElement.prototype, 'getScreenCTM', {
writable: true,
value: vi.fn(),
});
Object.defineProperty(global.SVGElement.prototype, 'getBBox', {
writable: true,
value: vi.fn().mockReturnValue({
x: 0,
y: 0,
}),
});
Object.defineProperty(global.SVGElement.prototype, 'getComputedTextLength', {
writable: true,
value: vi.fn().mockReturnValue(0),
});
Object.defineProperty(global.SVGElement.prototype, 'createSVGMatrix', {
writable: true,
value: vi.fn().mockReturnValue({
x: 10,
y: 10,
inverse: () => { null },
multiply: () => { null },
}),
});
window.URL.createObjectURL = function () {
return "";
};
if (typeof Worker === "undefined") {
global.Worker = class {
addEventListener() { null }
removeEventListener() { null }
dispatchEvent() { return false; }
onmessage() { null }
onmessageerror() { null }
onerror() { null }
postMessage() { null }
terminate() { null }
};
}
vi.mock('mapbox-gl', () => {
const mapboxglMock = {
Map: vi.fn(() => ({
addControl: vi.fn()
})),
Marker: vi.fn(() => ({
setLngLat: vi.fn(() => ({
addTo: vi.fn()
}))
})),
NavigationControl: vi.fn(),
FullscreenControl: vi.fn(),
addControl: vi.fn(),
};
return {
__esModule: true,
default: mapboxglMock,
...mapboxglMock
};
});