forked from sugarlabs/musicblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
39 lines (38 loc) · 1.04 KB
/
jest.setup.js
File metadata and controls
39 lines (38 loc) · 1.04 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
/**
* Global Jest setup for Music Blocks.
* This file contains global mocks and configurations for the test environment.
* Issue: https://github.com/sugarlabs/musicblocks/issues/5972
*/
// Mock HTMLCanvasElement.prototype.getContext to improve test stability and
// reduce console noise from jsdom not implementing canvas rendering.
HTMLCanvasElement.prototype.getContext = jest.fn(() => ({
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(),
fillStyle: "",
strokeStyle: "",
lineWidth: 1,
lineCap: "butt",
font: "10px sans-serif",
canvas: {
width: 800,
height: 600,
},
}));