-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
44 lines (36 loc) Β· 957 Bytes
/
jest.setup.js
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
const { JSDOM } = require('jsdom');
const raf = require('raf');
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
global.document = jsdom.window.document;
global.window = jsdom.window;
global.navigator = {
userAgent: 'node.js',
};
// Mock requestAnimationFrame
global.requestAnimationFrame = jest.fn((callback) => {
return raf(callback);
});
global.cancelAnimationFrame = (id) => {
raf.cancel(id);
};
// Mock window.scroll
global.window.scroll = jest.fn((x, y) => {
console.log(`Mocked scroll: x=${x}, y=${y}`);
});
// Additional polyfills
global.window.HTMLElement.prototype.scrollIntoView = jest.fn();
// Set up intersection observer mock
global.window.IntersectionObserver = class IntersectionObserver {
observe() {
// Do nothing
}
unobserve() {
// Do nothing
}
};
// Set up matchMedia mock
global.window.matchMedia = () => ({
matches: false,
addListener: () => {},
removeListener: () => {},
});