Skip to content

Commit f2021bd

Browse files
test(pagination): add test for changed total props to zero or negative
1 parent 91add5c commit f2021bd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/components/pagination/Pagination.spec.ts

+33
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ it('should render pagination items if "total" props is provided', () => {
3232
expect(paginationItems).toHaveLength(5)
3333
})
3434

35+
it('should render no pagination item if "total" props less than zero', () => {
36+
const screen = render({
37+
components: { Pagination },
38+
template : '<Pagination :total="-100" />',
39+
})
40+
41+
const pagination = screen.getByTestId('pagination')
42+
const paginationItems = screen.queryAllByTestId('pagination-item')
43+
44+
expect(pagination).toBeInTheDocument()
45+
expect(paginationItems).toHaveLength(0)
46+
})
47+
3548
it('should render only one page item if "total" props less than provided or default "per-page" props', () => {
3649
const screen = render({
3750
components: { Pagination },
@@ -290,6 +303,26 @@ it('should bind total page to "v-model", if total page count less than current p
290303
expect(model.value).toBe(5)
291304
})
292305

306+
it('should not change "v-model" to zero, if total pagination changed to zero', async () => {
307+
const model = ref(1)
308+
const total = ref(100)
309+
310+
render({
311+
components: { Pagination },
312+
template : '<Pagination v-model="model" :total="total" :per-page="10" />',
313+
setup () {
314+
return { model, total }
315+
},
316+
})
317+
318+
expect(model.value).toBe(1)
319+
320+
total.value = 0
321+
await nextTick()
322+
323+
expect(model.value).toBe(1)
324+
})
325+
293326
it('should not change "v-model", if ellipsis is clicked', async () => {
294327
const model = ref(1)
295328
const screen = render({

0 commit comments

Comments
 (0)