-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathjest.setup.js
More file actions
43 lines (39 loc) · 1013 Bytes
/
Copy pathjest.setup.js
File metadata and controls
43 lines (39 loc) · 1013 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
// Provide ErrorHandler global for tests
global.ErrorHandler = {
capture: jest.fn(),
warn: jest.fn(),
recoverable: jest.fn(),
userFacing: jest.fn()
};
// 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;
})
});