@@ -17,19 +17,30 @@ describe('InfiniteLoading.vue', () => {
17
17
isLoadedAll : false ,
18
18
isDivScroll : true ,
19
19
isCustomSpinner : false ,
20
+ listContainerHeight : 200 ,
21
+ listItemHeight : 20 ,
20
22
} ;
21
23
} ,
22
24
render ( createElement ) {
23
25
return createElement (
24
26
'div' ,
25
27
{
26
28
style : {
27
- height : '100px' ,
29
+ height : ` ${ this . listContainerHeight } px` ,
28
30
overflow : this . isDivScroll ? 'auto' : 'visible' ,
29
31
} ,
30
32
} ,
31
33
[
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 ) ) ) ,
33
44
this . isLoadedAll ? undefined : createElement ( InfiniteLoading ,
34
45
{
35
46
props : {
@@ -152,6 +163,8 @@ describe('InfiniteLoading.vue', () => {
152
163
vm . onInfinite = function test ( ) {
153
164
this . $refs . infiniteLoading . $emit ( '$InfiniteLoading:loaded' ) ;
154
165
this . $refs . infiniteLoading . $emit ( '$InfiniteLoading:complete' ) ;
166
+ // test for whether trigger again after complete
167
+ this . $refs . infiniteLoading . $emit ( '$InfiniteLoading:loaded' ) ;
155
168
Vue . nextTick ( ( ) => {
156
169
expect ( isShow ( vm . $el . querySelectorAll ( '.infinite-status-prompt' ) [ 1 ] ) ) . to . be . true ;
157
170
done ( ) ;
@@ -161,6 +174,29 @@ describe('InfiniteLoading.vue', () => {
161
174
vm . $mount ( '#app' ) ;
162
175
} ) ;
163
176
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
+
164
200
it ( 'should reset component and call onInfinite again' , ( done ) => {
165
201
let callCount = 0 ;
166
202
vm . onInfinite = function test ( ) {
0 commit comments