Skip to content

Commit f18fada

Browse files
committed
add test for isElementInView
1 parent a080a38 commit f18fada

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

__tests__/isElementInView.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import isElementInView from 'utils/isElementInView.js';
2+
3+
const element1 = {
4+
attributes: {
5+
top: 0,
6+
bottom: 500,
7+
},
8+
};
9+
10+
const element2 = {
11+
attributes: {
12+
top: 2500,
13+
bottom: 4000,
14+
},
15+
};
16+
17+
const windowHeight = 1000;
18+
19+
test('Returns whether an element is in view', () => {
20+
expect(isElementInView(element1, windowHeight, 1500)).toBe(false);
21+
expect(isElementInView(element1, windowHeight, 0)).toBe(true);
22+
expect(isElementInView(element2, 4000, 0)).toBe(true);
23+
expect(isElementInView(element2, windowHeight, 6500)).toBe(false);
24+
});

0 commit comments

Comments
 (0)