Skip to content

Commit bfccb2b

Browse files
committed
Modify the test case for continue fill up feature
1 parent 9cd0fcd commit bfccb2b

File tree

2 files changed

+21
-37
lines changed

2 files changed

+21
-37
lines changed

example/index.html

+2-4
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@
4040
onInfinite: function () {
4141
setTimeout(function () {
4242
var temp = [];
43-
for (var i = this.list.length; i <= this.list.length + 20; i++) {
43+
for (var i = this.list.length; i <= this.list.length + 10; i++) {
4444
temp.push(i);
4545
}
4646

4747
this.list = this.list.concat(temp);
48-
this.$nextTick(function () {
49-
this.$broadcast('$InfiniteLoading:loaded');
50-
});
48+
this.$broadcast('$InfiniteLoading:loaded');
5149
}.bind(this), 1000);
5250
}
5351
}

test/unit/specs/InfiniteLoading.spec.js

+19-33
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,25 @@ describe('InfiniteLoading.vue', () => {
1919
isLoadedAll: false,
2020
isDivScroll: true,
2121
isCustomSpinner: false,
22-
listContainerHeight: 100,
23-
listItemHeight: 10,
24-
customSpinnerHeight: 10,
22+
listContainerHeight: 200,
23+
listItemHeight: 20,
2524
},
2625
template: `
2726
<div style="margin: 0; padding: 0;"
2827
:style="{
2928
overflow: isDivScroll ? 'auto' : 'visible',
3029
height: listContainerHeight + 'px'
3130
}">
32-
<ul style="margin: 0; padding: 0; font-size: 5px;">
31+
<ul style="margin: 0; padding: 0;">
3332
<li v-for="item in list" v-text="item"
34-
style="height: 10px; margin: 0; padding: 0;"
35-
:style="{
36-
height: listItemHeight + 'px'
33+
:style="{ height: listItemHeight + 'px' }"
3734
}"></li>
3835
</ul>
3936
<infinite-loading :distance="distance"
4037
:on-infinite="onInfinite"
4138
v-if="!isLoadedAll">
4239
<span slot="spinner" v-if="isCustomSpinner">
43-
<i class="custom-spinner" style="display: inline-block; width: 10px;"
44-
:style="{
45-
height: customSpinnerHeight + 'px'
46-
}"></i>
40+
<i class="custom-spinner"></i>
4741
</span>
4842
</infinite-loading>
4943
</div>
@@ -145,32 +139,24 @@ describe('InfiniteLoading.vue', () => {
145139
vm.$mount().$appendTo('body');
146140
});
147141

148-
it('should load results to fill up the container', function fillUpTest(done) {
149-
const TEST_TIMEOUT = 2000;
150-
const mocha = this;
151-
let i = 0;
152-
vm.listContainerHeight = 100;
153-
vm.listItemHeight = 10;
154-
vm.distance = 10;
155-
vm.isCustomSpinner = true;
156-
vm.customSpinnerHeight = 10;
142+
it('should load results to fill up the container', (done) => {
157143
const expectedCount = Math.floor(vm.listContainerHeight / vm.listItemHeight);
144+
let i = 0;
145+
let timer;
158146

159147
vm.onInfinite = function test() {
160-
this.list.push(++i);
161-
Vue.nextTick(() => {
148+
setTimeout(() => {
149+
this.list.push(++i);
162150
this.$broadcast('$InfiniteLoading:loaded');
163-
if (i === expectedCount) {
164-
mocha.timeout(TEST_TIMEOUT + 100);
165-
setTimeout(() => {
166-
if (i === expectedCount) {
167-
done();
168-
} else {
169-
done(new Error('Unexpected number of items added'));
170-
}
171-
}, TEST_TIMEOUT);
172-
}
173-
});
151+
clearTimeout(timer);
152+
timer = setTimeout(() => {
153+
if (i >= expectedCount) {
154+
done();
155+
} else {
156+
done(new Error('List not be fill up!'));
157+
}
158+
}, 100);
159+
}, 1);
174160
}.bind(vm);
175161

176162
vm.$mount().$appendTo('body');

0 commit comments

Comments
 (0)