Skip to content

Commit

Permalink
Fix: currentPage becomes -1 when the list is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco van den Bout committed Jun 4, 2018
1 parent fcff039 commit e755eec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/Paginate.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ export default {
this.paginateList()
},
list () {
if (this.currentPage >= this.lastPage) {
if (this.currentPage >= this.lastPage && this.lastPage > 0) {
this.currentPage = this.lastPage - 1
} else {
this.currentPage = 0
}
this.paginateList()
},
Expand Down
8 changes: 8 additions & 0 deletions test/Paginate.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ describe('Paginate.vue', () => {
})
})

it('makes sure currentPage is not < 0 when list is empty', done => {
vm.langs = []
Vue.nextTick(() => {
expect(vm.paginate.langs.page).to.equal(0)
done()
})
})

it('allows `per` prop to be dynamic', (done) => {
vm = new Vue({
template: `
Expand Down

0 comments on commit e755eec

Please sign in to comment.