This repository has been archived by the owner on Jun 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 360
/
spec.js
57 lines (47 loc) · 1.48 KB
/
spec.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
53
54
55
56
57
import React from 'react';
import { mount } from 'enzyme';
import LazyLoad from './index';
let wrapper;
let onLazyLoad;
let makeComponent;
describe('<LazyLoad />', () => {
beforeEach(() => {
makeComponent = (isEnd = false, isLoading = false) => {
onLazyLoad = sinon.stub();
wrapper = mount(
<LazyLoad
onLazyLoad={onLazyLoad}
isEnd={isEnd}
isLoading={isLoading}
endComponent={<p>End</p>}
loadingComponent={<p>Loading</p>}
/>
);
};
makeComponent();
});
it('should render', () => {
expect(wrapper).to.be.ok; // eslint-disable-line
});
it('should show loading component', () => {
expect(wrapper.text()).to.eql('Loading');
});
it('should show end component when no more lazy loading needed', () => {
makeComponent(true);
expect(wrapper.text()).to.eql('End');
});
it('should call onLazyLoad when not end and not loading', () => {
wrapper.instance().onScroll();
expect(wrapper.props().onLazyLoad).to.have.been.called; // eslint-disable-line
});
it('should not call onLazyLoad when at end', () => {
makeComponent(true);
wrapper.instance().onScroll();
expect(wrapper.props().onLazyLoad).not.to.have.been.called; // eslint-disable-line
});
it('should not call onLazyLoad when loading', () => {
makeComponent(false, true);
wrapper.instance().onScroll();
expect(wrapper.props().onLazyLoad).not.to.have.been.called; // eslint-disable-line
});
});