This repository has been archived by the owner on Dec 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
getDocumentScrollHeight.spec.ts
50 lines (43 loc) · 2.08 KB
/
getDocumentScrollHeight.spec.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
43
44
45
46
47
48
49
50
import getDocumentScrollHeight from './getDocumentScrollHeight';
const CONFIGURABLE = {
writable: true,
configurable: true,
};
describe('getDocumentScrollHeight', () => {
it('should return the bodyScrollHeight', () => {
// For viewPortHeight
Object.defineProperty(document.documentElement, 'clientHeight', {value: 500, ...CONFIGURABLE});
Object.defineProperty(window, 'innerHeight', {value: 500, ...CONFIGURABLE});
// For scrollHeight
Object.defineProperty(document.documentElement, 'scrollHeight', {value: 500, ...CONFIGURABLE});
// For bodyScrollHeight
Object.defineProperty(document.body, 'scrollHeight', {value: 1500, ...CONFIGURABLE});
expect(getDocumentScrollHeight()).toEqual(1500);
});
it('should return the scrollHeight', () => {
// For viewPortHeight
Object.defineProperty(document.documentElement, 'clientHeight', {value: 500, ...CONFIGURABLE});
Object.defineProperty(window, 'innerHeight', {value: 500, ...CONFIGURABLE});
// For scrollHeight
Object.defineProperty(document.documentElement, 'scrollHeight', {value: 2250, ...CONFIGURABLE});
// For bodyScrollHeight
Object.defineProperty(document.body, 'scrollHeight', {value: 1500, ...CONFIGURABLE});
expect(getDocumentScrollHeight()).toEqual(2250);
});
it('should return the height of the largest node', () => {
// For viewPortHeight
Object.defineProperty(document.documentElement, 'clientHeight', {value: 1500, ...CONFIGURABLE});
Object.defineProperty(window, 'innerHeight', {value: 1500, ...CONFIGURABLE});
// For scrollHeight
Object.defineProperty(document.documentElement, 'scrollHeight', {value: 1500, ...CONFIGURABLE});
// For bodyScrollHeight
Object.defineProperty(document.body, 'scrollHeight', {value: 1500, ...CONFIGURABLE});
document.body.innerHTML =
'<div>' +
' <span style="height: 200px;width: 50px"/>' +
' <div style="height: 500px;width: 50px" />' +
'</div>';
// Some lines and the outcome can't be tested because we can't mock `scrollHeight` and `clientHeight`
getDocumentScrollHeight();
});
});