-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjest.setup.js
More file actions
109 lines (101 loc) · 2.65 KB
/
Copy pathjest.setup.js
File metadata and controls
109 lines (101 loc) · 2.65 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Jest setup for testing with DOM and Canvas
import { jest } from '@jest/globals';
// Mock the buttonHandlers module to prevent circular dependencies
jest.unstable_mockModule('@/buttonHandlers.js', () => ({
setupButtonListeners: jest.fn()
}));
// Mock the app.js module
jest.unstable_mockModule('@/app.js', () => ({
setupCanvas: jest.fn().mockReturnValue([
{ width: 800, height: 600, getContext: () => ({
clearRect: jest.fn(),
beginPath: jest.fn(),
moveTo: jest.fn(),
lineTo: jest.fn(),
stroke: jest.fn(),
fill: jest.fn(),
fillStyle: '',
strokeStyle: ''
})},
{ clearRect: jest.fn() }
]),
get_random_color: jest.fn().mockReturnValue('#ffffff'),
getQuantityOfDotsSelectedByUser: jest.fn().mockReturnValue(10)
}));
// Mock the appState module
jest.unstable_mockModule('@/state/appState.js', () => ({
setLastFunction: jest.fn(),
registerInterval: jest.fn((fn) => setInterval(fn, 100)),
registerAnimationFrame: jest.fn((fn) => requestAnimationFrame(fn)),
clearAllIntervals: jest.fn(() => {
const maxIntervalId = setInterval(() => {}, 10000);
for (let i = 0; i < maxIntervalId; i++) {
clearInterval(i);
}
}),
getLastFunction: jest.fn(),
resetState: jest.fn()
}));
// Mock basic DOM elements
global.document = {
getElementById: jest.fn().mockImplementation((id) => ({
id,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
value: '',
checked: false
})),
createElement: jest.fn().mockImplementation((tagName) => ({
tagName: tagName.toUpperCase(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
appendChild: jest.fn(),
setAttribute: jest.fn(),
style: {},
getContext: () => ({
clearRect: jest.fn(),
beginPath: jest.fn(),
moveTo: jest.fn(),
lineTo: jest.fn(),
stroke: jest.fn(),
fill: jest.fn(),
arc: jest.fn()
})
})),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
body: {
innerHTML: '',
appendChild: jest.fn(),
style: {}
},
documentElement: {
style: {}
}
};
global.window = {
requestAnimationFrame: jest.fn(cb => {
setTimeout(cb, 16);
return 1;
}),
cancelAnimationFrame: jest.fn(),
innerWidth: 800,
innerHeight: 600,
};
// Mock Canvas API
const mockContext = {
clearRect: jest.fn(),
beginPath: jest.fn(),
moveTo: jest.fn(),
lineTo: jest.fn(),
arc: jest.fn(),
fill: jest.fn(),
stroke: jest.fn(),
save: jest.fn(),
restore: jest.fn(),
fillStyle: '',
strokeStyle: '',
};
global.HTMLCanvasElement.prototype.getContext = jest.fn(() => mockContext);
// Make available globally
global.mockContext = mockContext;