forked from Predictify-org/predictify-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
59 lines (52 loc) · 1.42 KB
/
Copy pathjest.setup.js
File metadata and controls
59 lines (52 loc) · 1.42 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
import '@testing-library/jest-dom'
// Mock IntersectionObserver
global.IntersectionObserver = class IntersectionObserver {
constructor() {}
disconnect() {}
observe() {}
unobserve() {}
}
// Mock ResizeObserver
global.ResizeObserver = class ResizeObserver {
constructor() {}
disconnect() {}
observe() {}
unobserve() {}
}
// Mock scrollTo for testing scroll behavior
Object.defineProperty(window, 'scrollTo', {
value: jest.fn(),
writable: true
})
// Mock requestAnimationFrame for count-up / animation hooks.
// Each call advances the timestamp by 500 ms so animations complete
// within two frames (500 ms > the hook's 400 ms default duration).
// Reset the clock before each test to prevent timestamp drift across suites.
let rAFTime = 0;
global.requestAnimationFrame = (cb) => {
const time = rAFTime;
rAFTime += 500;
cb(time);
return 1;
};
global.cancelAnimationFrame = () => {};
beforeEach(() => {
rAFTime = 0;
});
// Mock HTMLElement scrollTo
Object.defineProperty(HTMLElement.prototype, 'scrollTo', {
value: jest.fn(),
writable: true
})
// Suppress console.error for known React warnings in tests
const originalError = console.error;
console.error = (...args) => {
if (
typeof args[0] === 'string' &&
(args[0].includes('Received `true` for a non-boolean attribute `fill`') ||
args[0].includes('non-boolean attribute `fill`'))
) {
return;
}
originalError.call(console, ...args);
};