-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
executable file
·52 lines (38 loc) · 1.37 KB
/
test.js
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 LazyLoadImage from './index.js';
describe('lazy-load-image', () => {
describe('isElementLazyLoadable', () => {
test('element is not an image', async () => {
await expect(LazyLoadImage.isElementLazyLoadable(mockHtmlElement('div'))).toEqual(false);
});
test('element does not have custom lazy load data attribute', async () => {
await expect(LazyLoadImage.isElementLazyLoadable(mockHtmlElement('img'))).toEqual(false);
});
test('element is lazy load-able', async () => {
await expect(LazyLoadImage.isElementLazyLoadable(mockHtmlElement('img', { 'data-lazyload': 'localhost' }))).toEqual(true);
});
});
describe('IntersectionObserver options', () => {
test('match the default', async () => {
const expectedDefaultOptions = {
root: null,
rootMargin: '200px',
threshold: 0,
};
const lazyLoader = new LazyLoadImage('#targetElement');
await expect(lazyLoader.getIntersectionObserverOptions()).toEqual(expectedDefaultOptions);
});
test('match the passed in rootMargin', async () => {
const expectedOptions = {
root: null,
rootMargin: '400px',
threshold: 0,
};
const lazyLoader = new LazyLoadImage('#targetElement', '400px');
await expect(lazyLoader.getIntersectionObserverOptions()).toEqual(expectedOptions);
});
});
const mockHtmlElement = (nodeName, attributes = {}) => ({
nodeName,
attributes,
});
});