forked from ankeetmaini/react-infinite-scroll-component
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbottom.test.tsx
More file actions
52 lines (44 loc) · 1.15 KB
/
bottom.test.tsx
File metadata and controls
52 lines (44 loc) · 1.15 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
import { render, cleanup } from '@testing-library/react';
import InfiniteScroll from '../index';
describe('bottom detection triggers next', () => {
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
cleanup();
jest.useRealTimers();
});
it('calls next when scrolled to bottom (height container)', () => {
const next = jest.fn();
const { container } = render(
<InfiniteScroll
dataLength={0}
loader={'Loading...'}
hasMore={true}
next={next}
height={100}
scrollThreshold="0px"
>
<div />
</InfiniteScroll>
);
const node = container.querySelector(
'.infinite-scroll-component'
) as HTMLElement;
Object.defineProperty(node, 'clientHeight', {
configurable: true,
get: () => 100,
});
Object.defineProperty(node, 'scrollHeight', {
configurable: true,
get: () => 200,
});
Object.defineProperty(node, 'scrollTop', {
configurable: true,
get: () => 100,
});
node.dispatchEvent(new Event('scroll'));
jest.advanceTimersByTime(200);
expect(next).toHaveBeenCalled();
});
});