-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
38 lines (37 loc) · 1.12 KB
/
jest.setup.js
File metadata and controls
38 lines (37 loc) · 1.12 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
// Jest setup file to mock Canvas for Phaser in jsdom environments
// This mock prevents Phaser from crashing when it calls getContext('2d') on a canvas in jsdom.
// See common-issues.md for details.
Object.defineProperty(HTMLCanvasElement.prototype, 'getContext', {
value: function (type) {
if (type === '2d') {
// Return a minimal mock context with just enough for Phaser to not crash
return {
fillStyle: '',
fillRect: () => {},
clearRect: () => {},
getImageData: () => ({ data: [] }),
putImageData: () => {},
createImageData: () => [],
setTransform: () => {},
drawImage: () => {},
save: () => {},
restore: () => {},
beginPath: () => {},
moveTo: () => {},
lineTo: () => {},
closePath: () => {},
stroke: () => {},
translate: () => {},
scale: () => {},
rotate: () => {},
arc: () => {},
fill: () => {},
measureText: () => ({ width: 0 }),
transform: () => {},
rect: () => {},
clip: () => {},
};
}
return null;
},
});