-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathjest.setup.js
More file actions
35 lines (32 loc) · 849 Bytes
/
jest.setup.js
File metadata and controls
35 lines (32 loc) · 849 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
// Mock HTMLCanvasElement.getContext to suppress jsdom warnings
const mockContext = {
clearRect: jest.fn(),
fillRect: jest.fn(),
beginPath: jest.fn(),
moveTo: jest.fn(),
lineTo: jest.fn(),
stroke: jest.fn(),
fill: jest.fn(),
closePath: jest.fn(),
ellipse: jest.fn(),
arc: jest.fn(),
drawImage: jest.fn(),
measureText: jest.fn(() => ({
width: 0,
actualBoundingBoxAscent: 0,
actualBoundingBoxDescent: 0,
})),
scale: jest.fn(),
setTransform: jest.fn(),
save: jest.fn(),
restore: jest.fn(),
};
Object.defineProperty(HTMLCanvasElement.prototype, 'getContext', {
configurable: true,
writable: true,
value: jest.fn((type) => {
// Return null for non-2d contexts
if (type !== '2d') return null;
return mockContext;
}),
});