-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.setup.js
More file actions
49 lines (44 loc) · 887 Bytes
/
jest.setup.js
File metadata and controls
49 lines (44 loc) · 887 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
44
45
46
47
48
49
import '@testing-library/jest-dom';
global.URL.createObjectURL = jest.fn(() => 'mock-url');
global.URL.revokeObjectURL = jest.fn();
HTMLCanvasElement.prototype.getContext = jest.fn((type) => {
if (type === '2d') {
const imageData = {
data: new Uint8ClampedArray(400 * 400 * 4).fill(128),
width: 400,
height: 400
};
return {
drawImage: jest.fn(),
getImageData: jest.fn(() => imageData),
putImageData: jest.fn(),
clearRect: jest.fn(),
fillRect: jest.fn(),
fillText: jest.fn(),
measureText: jest.fn(() => ({ width: 10 }))
};
}
return null;
});
global.Image = class MockImage {
constructor() {
this.crossOrigin = '';
setTimeout(() => {
if (this.onload) {
this.onload();
}
}, 0);
}
get width() {
return 400;
}
get height() {
return 400;
}
set src(value) {
this._src = value;
}
get src() {
return this._src;
}
};