-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjest.setup.js
More file actions
94 lines (88 loc) · 2.23 KB
/
jest.setup.js
File metadata and controls
94 lines (88 loc) · 2.23 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
import '@testing-library/jest-dom'
// Mock Web Audio API
global.AudioContext = jest.fn().mockImplementation(() => ({
createAnalyser: jest.fn().mockReturnValue({
fftSize: 2048,
frequencyBinCount: 1024,
getByteFrequencyData: jest.fn(),
getFloatTimeDomainData: jest.fn(),
connect: jest.fn(),
disconnect: jest.fn(),
}),
createGain: jest.fn().mockReturnValue({
gain: { value: 1 },
connect: jest.fn(),
disconnect: jest.fn(),
}),
createScriptProcessor: jest.fn().mockReturnValue({
connect: jest.fn(),
disconnect: jest.fn(),
onaudioprocess: null,
}),
createMediaStreamSource: jest.fn().mockReturnValue({
connect: jest.fn(),
disconnect: jest.fn(),
}),
sampleRate: 48000,
close: jest.fn().mockResolvedValue(undefined),
destination: {},
}))
// Mock MediaDevices API
Object.defineProperty(global.navigator, 'mediaDevices', {
writable: true,
value: {
getUserMedia: jest.fn().mockResolvedValue({
getTracks: jest.fn().mockReturnValue([
{
stop: jest.fn(),
kind: 'audio',
},
]),
}),
},
})
// Mock Canvas API
HTMLCanvasElement.prototype.getContext = jest.fn().mockReturnValue({
fillStyle: '',
fillRect: jest.fn(),
clearRect: jest.fn(),
getImageData: jest.fn(),
putImageData: jest.fn(),
createImageData: jest.fn(),
setTransform: jest.fn(),
drawImage: jest.fn(),
save: jest.fn(),
restore: jest.fn(),
scale: jest.fn(),
rotate: jest.fn(),
translate: jest.fn(),
transform: jest.fn(),
beginPath: jest.fn(),
closePath: jest.fn(),
moveTo: jest.fn(),
lineTo: jest.fn(),
bezierCurveTo: jest.fn(),
quadraticCurveTo: jest.fn(),
arc: jest.fn(),
arcTo: jest.fn(),
ellipse: jest.fn(),
rect: jest.fn(),
fill: jest.fn(),
stroke: jest.fn(),
clip: jest.fn(),
isPointInPath: jest.fn(),
isPointInStroke: jest.fn(),
measureText: jest.fn().mockReturnValue({ width: 0 }),
canvas: document.createElement('canvas'),
})
HTMLCanvasElement.prototype.toBlob = jest.fn((callback) => {
callback(new Blob(['fake-image-data'], { type: 'image/png' }))
})
// Suppress console errors in tests
const originalError = console.error
beforeAll(() => {
console.error = jest.fn()
})
afterAll(() => {
console.error = originalError
})