Skip to content

Commit a2e95c7

Browse files
authored
Update table-sort.spec.js
1 parent 090ba4b commit a2e95c7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/components/table/table-sort.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Table from './table'
2+
import defaultSortCompare from './helpers/default-sort-compare'
23
import { mount } from '@vue/test-utils'
34

45
const testItems = [{ a: 3, b: 'b', c: 'x' }, { a: 1, b: 'c', c: 'y' }, { a: 2, b: 'a', c: 'z' }]
@@ -107,4 +108,40 @@ describe('table sorting', () => {
107108
expect(columnA[1]).toBe('1')
108109
expect(columnA[2]).toBe('2')
109110
})
111+
112+
it('should accept custom sort compare', async () => {
113+
const wrapper = mount(Table, {
114+
propsData: {
115+
fields: testFields,
116+
items: testItems,
117+
sortBy: 'a',
118+
sortDesc: false,
119+
sortCompare: (a, b, sortBy) => {
120+
// We just use our default sort compare to test passing a function
121+
return defaultSortCompare(a, b, sortBy)
122+
})
123+
}
124+
})
125+
expect(wrapper).toBeDefined()
126+
expect(wrapper.findAll('tbody > tr').exists()).toBe(true)
127+
expect(wrapper.findAll('tbody > tr').length).toBe(3)
128+
let $rows
129+
let columnA
130+
131+
await wrapper.vm.$nextTick()
132+
expect(wrapper.emitted('input')).toBeDefined()
133+
expect(wrapper.emitted('input').length).toBe(1)
134+
$rows = wrapper.findAll('tbody > tr').wrappers
135+
expect($rows.length).toBe(3)
136+
// Map the rows to the first column text value
137+
columnA = $rows.map(row => {
138+
return row
139+
.findAll('td')
140+
.at(0)
141+
.text()
142+
})
143+
expect(columnA[0]).toBe('1')
144+
expect(columnA[1]).toBe('2')
145+
expect(columnA[2]).toBe('3')
146+
})
110147
})

0 commit comments

Comments
 (0)