8000 test: add test case for scroll height restore feature · PeachScript/vue-infinite-loading@b75442a · GitHub
[go: up one dir, main page]

Skip to content

Commit b75442a

Browse files
committed
test: add test case for scroll height restore feature
1 parent d2c41e2 commit b75442a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/unit/specs/InfiniteLoading.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,4 +682,38 @@ describe('vue-infinite-loading:component', () => {
682682

683683
vm.$mount('#app');
684684
});
685+
686+
it('should save and restore scroll bar when using top direction', (done) => {
687+
vm = new Vue(Object.assign({}, basicConfig, {
688+
data: {
689+
list: [1, 2, 3, 4, 5],
690+
},
691+
template: `
692+
<div style="overflow: auto; height: 100px;">
693+
<ul>
694+
<li v-for="item in list" v-text="item"></li>
695+
</ul>
696+
<infinite-loading
697+
direction="top"
698+
@infinite="infiniteHandler">
699+
</infinite-loading>
700+
</div>
701+
`,
702+
methods: {
703+
infiniteHandler($state) {
704+
expect(this.$el.scrollTop).to.equal(0);
705+
this.list.push(6, 7, 8, 9, 10);
706+
$state.loaded();
707+
708+
// wait for scroll bar restore
709+
setTimeout(() => {
710+
expect(this.$el.scrollTop).to.not.equal(0);
711+
done();
712+
}, 100);
713+
},
714+
},
715+
}));
716+
717+
vm.$mount('#app');
718+
});
685719
});

0 commit comments

Comments
 (0)
0