-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathjest.setup.js
More file actions
51 lines (46 loc) · 1.09 KB
/
jest.setup.js
File metadata and controls
51 lines (46 loc) · 1.09 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
40
41
42
43
44
45
46
47
48
49
50
51
// Jest setup file
require('@testing-library/jest-dom');
// Mock localStorage
const localStorageMock = {
getItem: jest.fn(),
setItem: jest.fn(),
removeItem: jest.fn(),
clear: jest.fn(),
};
global.localStorage = localStorageMock;
// Mock Audio
global.Audio = jest.fn().mockImplementation(() => ({
play: jest.fn(() => Promise.resolve()),
pause: jest.fn(),
currentTime: 0,
volume: 1,
}));
// Mock canvas
HTMLCanvasElement.prototype.getContext = jest.fn(() => ({
fillRect: jest.fn(),
clearRect: jest.fn(),
fillStyle: '',
strokeStyle: '',
lineWidth: 1,
beginPath: jest.fn(),
moveTo: jest.fn(),
lineTo: jest.fn(),
stroke: jest.fn(),
fill: jest.fn(),
arc: jest.fn(),
createRadialGradient: jest.fn(() => ({
addColorStop: jest.fn(),
})),
setLineDash: jest.fn(),
strokeRect: jest.fn(),
}));
// Mock fetch
global.fetch = jest.fn(() =>
Promise.resolve({
ok: true,
json: () => Promise.resolve({}),
})
);
// Mock requestAnimationFrame
global.requestAnimationFrame = jest.fn((cb) => setTimeout(cb, 16));
global.cancelAnimationFrame = jest.fn((id) => clearTimeout(id));