table-tbody-transition.spec.js
2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { config as vtuConfig, mount } from '@vue/test-utils'
import { TransitionGroupStub } from '../../../tests/components'
import { isVue3 } from '../../vue'
import { BTable } from './table'
// Stub `<transition-group>` component
if (!isVue3) {
vtuConfig.stubs['transition-group'] = TransitionGroupStub
}
const testItems = [{ a: 1, b: 2, c: 3 }, { a: 5, b: 5, c: 6 }, { a: 7, b: 8, c: 9 }]
const testFields = ['a', 'b', 'c']
describe('table > tbody transition', () => {
if (isVue3) {
// @vue/test-utils does not support stubbing transition, so impossible to test ATM
// adding dummy test to keep jest happy
it('skipped due to vue3', () => {})
return
}
it('tbody should not be a transition-group component by default', async () => {
const wrapper = mount(BTable, {
attachTo: document.body,
propsData: {
fields: testFields,
items: testItems
}
})
expect(wrapper).toBeDefined()
expect(wrapper.element.tagName).toBe('TABLE')
expect(wrapper.find('tbody').exists()).toBe(true)
expect(wrapper.find('tbody').element.tagName).toBe('TBODY')
// `<transition-group>` stub doesn't render itself with the specified tag
expect(wrapper.findComponent(TransitionGroupStub).exists()).toBe(false)
wrapper.destroy()
})
it('tbody should be a transition-group component when tbody-transition-props set', async () => {
const wrapper = mount(BTable, {
attachTo: document.body,
propsData: {
fields: testFields,
items: testItems,
tbodyTransitionProps: {
name: 'fade'
}
}
})
expect(wrapper).toBeDefined()
expect(wrapper.element.tagName).toBe('TABLE')
// `<transition-group>` stub doesn't render itself with the specified tag
expect(wrapper.findComponent(TransitionGroupStub).exists()).toBe(true)
expect(wrapper.find('tbody').exists()).toBe(false)
wrapper.destroy()
})
it('tbody should be a transition-group component when tbody-transition-handlers set', async () => {
const wrapper = mount(BTable, {
attachTo: document.body,
propsData: {
fields: testFields,
items: testItems,
tbodyTransitionHandlers: {
onBeforeEnter: () => {},
onAfterEnter: () => {},
onBeforeLeave: () => {},
onAfterLeave: () => {}
}
}
})
expect(wrapper).toBeDefined()
expect(wrapper.element.tagName).toBe('TABLE')
// `<transition-group>` stub doesn't render itself with the specified tag
expect(wrapper.findComponent(TransitionGroupStub).exists()).toBe(true)
expect(wrapper.find('tbody').exists()).toBe(false)
wrapper.destroy()
})
})