-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjest.setup.ts
42 lines (34 loc) · 1.18 KB
/
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
39
40
41
42
import '@testing-library/jest-dom';
class IntersectionObserver {
root: Element | Document | null;
rootMargin: string;
thresholds: ReadonlyArray<number>;
callback: IntersectionObserverCallback;
options?: IntersectionObserverInit;
constructor(callback: IntersectionObserverCallback, options?: IntersectionObserverInit) {
this.callback = callback;
this.options = options;
this.root = options?.root || null;
this.rootMargin = options?.rootMargin || '0px';
this.thresholds = options?.threshold ? (Array.isArray(options.threshold) ? options.threshold : [options.threshold]) : [0];
}
observe(target: Element) {
const entry: IntersectionObserverEntry = {
time: Date.now(),
target,
isIntersecting: true,
intersectionRatio: 1,
intersectionRect: target.getBoundingClientRect(),
boundingClientRect: target.getBoundingClientRect(),
rootBounds: this.root ? (this.root as Element).getBoundingClientRect() : null,
};
this.callback([entry], this);
}
unobserve() {}
disconnect() {}
takeRecords(): IntersectionObserverEntry[] {
return [];
}
}
(global as any).IntersectionObserver = IntersectionObserver;
export {};