-
Notifications
You must be signed in to change notification settings - Fork 2
/
jest-setup.ts
38 lines (33 loc) · 868 Bytes
/
jest-setup.ts
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
import { act } from 'react';
import { TextEncoder, TextDecoder } from 'util';
import '@testing-library/jest-dom';
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
beforeEach(() => {
jest.useFakeTimers();
let time = 0;
jest.spyOn(window, 'requestAnimationFrame').mockImplementation((callback) => {
setTimeout(() => {
time += 100;
callback(time);
});
return time;
});
});
afterEach(() => {
(window.requestAnimationFrame as jest.Mock).mockRestore();
act(() => {
jest.runOnlyPendingTimers();
});
jest.useRealTimers();
});
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
global.IntersectionObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));