Skip to content

Commit a96468e

Browse files
committed
Add unit test for the continue fill up feature
1 parent fc98f8e commit a96468e

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

test/unit/specs/InfiniteLoading.spec.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,30 @@ describe('InfiniteLoading.vue', () => {
1717
isLoadedAll: false,
1818
isDivScroll: true,
1919
isCustomSpinner: false,
20+
listContainerHeight: 200,
21+
listItemHeight: 20,
2022
};
2123
},
2224
render(createElement) {
2325
return createElement(
2426
'div',
2527
{
2628
style: {
27-
height: '100px',
29+
height: `${this.listContainerHeight}px`,
2830
overflow: this.isDivScroll ? 'auto' : 'visible',
2931
},
3032
},
3133
[
32-
createElement('ul', this.list.map((item) => createElement('li', item))),
34+
createElement('ul', {
35+
style: {
36+
margin: 0,
37+
padding: 0,
38+
},
39+
}, this.list.map((item) => createElement('li', {
40+
style: {
41+
height: `${this.listItemHeight}px`,
42+
},
43+
}, item))),
3344
this.isLoadedAll ? undefined : createElement(InfiniteLoading,
3445
{
3546
props: {
@@ -152,6 +163,8 @@ describe('InfiniteLoading.vue', () => {
152163
vm.onInfinite = function test() {
153164
this.$refs.infiniteLoading.$emit('$InfiniteLoading:loaded');
154165
this.$refs.infiniteLoading.$emit('$InfiniteLoading:complete');
166+
// test for whether trigger again after complete
167+
this.$refs.infiniteLoading.$emit('$InfiniteLoading:loaded');
155168
Vue.nextTick(() => {
156169
expect(isShow(vm.$el.querySelectorAll('.infinite-status-prompt')[1])).to.be.true;
157170
done();
@@ -161,6 +174,29 @@ describe('InfiniteLoading.vue', () => {
161174
vm.$mount('#app');
162175
});
163176

177+
it('should load results to fill up the container', (done) => {
178+
const expectedCount = Math.floor(vm.listContainerHeight / vm.listItemHeight);
179+
let i = 0;
180+
let timer;
181+
182+
vm.onInfinite = function test() {
183+
setTimeout(() => {
184+
this.list.push(++i);
185+
this.$refs.infiniteLoading.$emit('$InfiniteLoading:loaded');
186+
clearTimeout(timer);
187+
timer = setTimeout(() => {
188+
if (i >= expectedCount) {
189+
done();
190+
} else {
191+
done(new Error('List not be fill up!'));
192+
}
193+
}, 100);
194+
}, 1);
195+
}.bind(vm);
196+
197+
vm.$mount('#app');
198+
});
199+
164200
it('should reset component and call onInfinite again', (done) => {
165201
let callCount = 0;
166202
vm.onInfinite = function test() {

0 commit comments

Comments
 (0)