Skip to content

Commit fc08a36

Browse files
committed
Add unit test for the force-use-infinite-wrapper feature and the corresponding warning
1 parent a25fcf6 commit fc08a36

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

test/unit/specs/InfiniteLoading.spec.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,81 @@ describe('vue-infinite-loading', () => {
434434

435435
vm.$mount('#app');
436436
});
437+
438+
it('should find my forcible element as scroll wrapper when using `force-use-infinite-wrapper` attribute', (done) => {
439+
vm = new Vue(Object.assign({}, basicConfig, {
440+
template: `
441+
<div infinite-wrapper>
442+
<div style="overflow: auto;">
443+
<div style="overflow: auto;">
444+
<ul>
445+
<li v-for="item in list" v-text="item"></li>
446+
</ul>
447+
<infinite-loading
448+
:direction="direction"
449+
@infinite="infiniteHandler"
450+
ref="infiniteLoading"
451+
force-use-infinite-wrapper="true"
452+
>
453+
</infinite-loading>
454+
</div>
455+
</div>
456+
</div>
457+
`,
458+
methods: {
459+
infiniteHandler: function infiniteHandler() {
460+
expect(this.$refs.infiniteLoading.scrollParent).to.equal(this.$el);
461+
done();
462+
},
463+
},
464+
}));
465+
466+
vm.$mount('#app');
467+
});
468+
469+
it('should throw error when the component be in a infinite loop caused by a wrapper with unfixed height', (done) => {
470+
const originalError = console.error;
471+
let isThrowError;
472+
473+
console.error = (text) => {
474+
if (text.indexOf('issues/55') > -1) {
475+
isThrowError = true;
476+
}
477+
};
478+
479+
vm = new Vue(Object.assign({}, basicConfig, {
480+
template: `
481+
<div style="overflow: auto; height: auto;">
482+
<ul>
483+
<li v-for="item in list" v-text="item"></li>
484+
</ul>
485+
<infinite-loading
486+
:direction="direction"
487+
@infinite="infiniteHandler"
488+
ref="infiniteLoading"
489+
>
490+
</infinite-loading>
491+
</div>
492+
`,
493+
methods: {
494+
infiniteHandler: function infiniteHandler($state) {
495+
if (!isThrowError) {
496+
this.list.push(this.list.length + 1);
497+
$state.loaded();
498+
} else {
499+
$state.complete();
500+
expect(isThrowError).to.be.true;
501+
console.error = originalError;
502+
// wait for the loop check flag be marked as true
503+
setTimeout(() => {
504+
expect(this.$refs.infiniteLoading.infiniteLoopChecked).to.be.true;
505+
done();
506+
}, 1501);
507+
}
508+
},
509+
},
510+
}));
511+
512+
vm.$mount('#app');
513+
});
437514
});

0 commit comments

Comments
 (0)