Skip to content

Commit e215c37

Browse files
committed
Added more important tests
1 parent 44ec472 commit e215c37

File tree

1 file changed

+88
-16
lines changed

1 file changed

+88
-16
lines changed

Diff for: __tests__/TinyPagination.spec.js

+88-16
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,108 @@
11
import {mount} from 'vue-test-utils'
22
import TinyPagination from '../src/components/TinyPagination.vue'
3+
import { create } from 'domain';
34

45
// Helper function to create a component
56
const createComponent = propsData => mount(TinyPagination, {propsData})
67

78
describe('TinyPagination.vue', () => {
89
let cmp
9-
1010
it('has a created hook', () => {
1111
expect(typeof TinyPagination.created).toBe('function')
1212
})
1313

14-
it('when the page property is set, the currentPage is equals', () => {
15-
cmp = createComponent({total: 300, page: 2})
16-
expect(cmp.vm.currentPage).toBe(2)
17-
})
14+
describe('Properties', () => {
15+
it('when the component is created without page prop, Page 1 is the page by default', () => {
16+
cmp = createComponent({total: 300})
17+
expect(cmp.vm.page).toBe(1)
18+
})
19+
20+
it('when the page property is set, the currentPage is equals', () => {
21+
cmp = createComponent({total: 300, page: 2})
22+
expect(cmp.vm.currentPage).toBe(2)
23+
})
24+
25+
it('when the component is created, English is the language by default', () => {
26+
cmp = createComponent({total: 300})
27+
expect(cmp.vm.lang).toBe('en')
28+
expect(cmp.vm.translation.title).toBe('Page')
29+
})
30+
31+
it('when the lang prop is set to spanish, the component is translated', () => {
32+
cmp = createComponent({total: 300, lang: 'es'})
33+
expect(cmp.vm.lang).toBe('es')
34+
expect(cmp.vm.translation.title).toBe('Página')
35+
})
1836

19-
it('when the component is created without page prop, Page 1 is the page by default', () => {
20-
cmp = createComponent({total: 300})
21-
expect(cmp.vm.page).toBe(1)
37+
it('when the lang prop is set to not available language, English is the language by default', () => {
38+
cmp = createComponent({total: 300, lang: 'fr'})
39+
expect(cmp.vm.translation.title).toBe('Page')
40+
})
2241
})
2342

24-
it('when the component is created, English is the language by default', () => {
25-
cmp = createComponent({total: 300})
26-
expect(cmp.vm.lang).toBe('en')
27-
expect(cmp.vm.translation.title).toBe('Page')
43+
describe('Watchers', () => {
44+
45+
it('currentPage watcher is called with the new value', () => {
46+
let spy = jest.fn()
47+
cmp = createComponent({total: 100})
48+
cmp.vm.$watch('currentPage', spy)
49+
50+
cmp.setData({currentPage: 3})
51+
cmp.update()
52+
53+
expect(spy).toBeCalled()
54+
})
55+
56+
it('currentLimit watcher is called with the new value', () => {
57+
let spy = jest.fn()
58+
cmp = createComponent({total: 200})
59+
cmp.vm.$watch('currentLimit', spy)
60+
61+
cmp.setData({currentLimit: 20})
62+
cmp.update()
63+
64+
expect(spy).toBeCalled()
65+
})
66+
67+
it('when the currentPage watcher is called, the tiny:change-page event is emitted', () => {
68+
let stub = jest.fn()
69+
cmp = createComponent({total: 100})
70+
cmp.vm.$on('tiny:change-page', stub)
71+
72+
cmp.setData({currentPage: 3})
73+
expect(stub).toBeCalledWith({page: 3})
74+
})
75+
76+
it('when the currentLimit watcher is called, the tiny:change-limit event is emitted', () => {
77+
let stub = jest.fn()
78+
cmp = createComponent({total: 100})
79+
cmp.vm.$on('tiny:change-limit', stub)
80+
81+
cmp.setData({currentLimit: 20})
82+
expect(stub).toBeCalledWith({limit: 20})
83+
})
2884
})
2985

30-
it('when the lang prop is set to spanish, the component is translated', () => {
31-
cmp = createComponent({total: 300, lang: 'es'})
32-
expect(cmp.vm.lang).toBe('es')
33-
expect(cmp.vm.translation.title).toBe('Página')
86+
describe('Events', () => {
87+
beforeEach(() => {
88+
cmp = createComponent({total: 20})
89+
})
90+
91+
it('calls nextPage when click on next button', () => {
92+
cmp.vm.nextPage = jest.fn()
93+
cmp.update()
94+
95+
const el = cmp.find('.btn-next-page').trigger('click')
96+
expect(cmp.vm.nextPage).toBeCalled()
97+
})
98+
99+
it('call lastPage when click on prev button', () => {
100+
cmp.vm.lastPage = jest.fn()
101+
cmp.update()
102+
103+
const el = cmp.find('.btn-prev-page').trigger('click')
104+
expect(cmp.vm.lastPage).toBeCalled()
105+
})
34106
})
35107

36108
})

0 commit comments

Comments
 (0)