Skip to content

Commit cbcd8e4

Browse files
nekosaurjohnleider
authored andcommitted
fix(VDataTable): items-per-page event should not emit immediately (#9615)
closes #9599
1 parent bdb9f0a commit cbcd8e4

File tree

3 files changed

+722
-20
lines changed

3 files changed

+722
-20
lines changed

packages/vuetify/src/components/VData/VData.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,8 @@ export default Vue.extend({
222222
itemsPerPage (itemsPerPage: number) {
223223
this.updateOptions({ itemsPerPage })
224224
},
225-
'internalOptions.itemsPerPage': {
226-
handler (itemsPerPage: number) {
227-
this.$emit('update:items-per-page', itemsPerPage)
228-
},
229-
immediate: true,
225+
'internalOptions.itemsPerPage' (itemsPerPage: number) {
226+
this.$emit('update:items-per-page', itemsPerPage)
230227
},
231228
sortBy (sortBy: string | string[]) {
232229
this.updateOptions({ sortBy: wrapInArray(sortBy) })

packages/vuetify/src/components/VDataTable/__tests__/VDataTable.spec.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -509,45 +509,51 @@ describe('VDataTable.ts', () => {
509509

510510
// https://github.com/vuetifyjs/vuetify/issues/8184
511511
it('should default to first option in itemsPerPageOptions if it does not include itemsPerPage', async () => {
512-
const itemsPerPage = jest.fn()
513-
const options = jest.fn()
514512
const wrapper = mountFunction({
515513
propsData: {
516514
headers: testHeaders,
517515
items: testItems,
518516
footerProps: {
519-
itemsPerPageOptions: [5, 6],
517+
itemsPerPageOptions: [6, 7],
520518
},
521519
},
522-
listeners: {
523-
'update:items-per-page': itemsPerPage,
524-
'update:options': options,
525-
},
526520
})
527521

528-
expect(itemsPerPage).toHaveBeenCalledWith(5)
529-
expect(options).toHaveBeenCalledWith(expect.objectContaining({
530-
itemsPerPage: 5,
531-
}))
522+
expect(wrapper.html()).toMatchSnapshot()
532523
})
533524

534525
// https://github.com/vuetifyjs/vuetify/issues/8817
535526
it('should handle object when checking if it should default to first option in itemsPerPageOptions', async () => {
536-
const itemsPerPage = jest.fn()
537527
const wrapper = mountFunction({
538528
propsData: {
539529
headers: testHeaders,
540530
items: testItems,
541531
itemsPerPage: -1,
542532
footerProps: {
543-
itemsPerPageOptions: [5, 6, { text: 'All', value: -1 }],
533+
itemsPerPageOptions: [6, { text: 'All', value: -1 }],
534+
},
535+
},
536+
})
537+
538+
expect(wrapper.html()).toMatchSnapshot()
539+
})
540+
541+
// https://github.com/vuetifyjs/vuetify/issues/9599
542+
it('should not immediately emit items-per-page', async () => {
543+
const itemsPerPage = jest.fn()
544+
const wrapper = mountFunction({
545+
propsData: {
546+
headers: testHeaders,
547+
items: testItems,
548+
footerProps: {
549+
itemsPerPageOptions: [6, 7],
544550
},
545551
},
546552
listeners: {
547-
'update:items-per-page': itemsPerPage,
553+
'update:itemsPerPage': itemsPerPage,
548554
},
549555
})
550556

551-
expect(itemsPerPage).toHaveBeenCalledWith(-1)
557+
expect(itemsPerPage).not.toHaveBeenCalled()
552558
})
553559
})

0 commit comments

Comments
 (0)