Skip to content

Commit 95f0d16

Browse files
authored
chore(unit tests): more test conversion (#2929)
1 parent 4705091 commit 95f0d16

File tree

8 files changed

+291
-299
lines changed

8 files changed

+291
-299
lines changed
Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,80 @@
1-
import { loadFixture, testVM } from '../../../tests/utils'
1+
import ButtonGroup from './button-group'
2+
import { mount } from '@vue/test-utils'
23

34
describe('button-group', () => {
4-
beforeEach(loadFixture(__dirname, 'button-group'))
5-
testVM()
6-
7-
it('basic should contain base class', async () => {
8-
const {
9-
app: { $refs }
10-
} = window
5+
it('has expected default structure', async () => {
6+
const wrapper = mount(ButtonGroup)
7+
expect(wrapper.is('div')).toBe(true)
8+
expect(wrapper.classes()).toContain('btn-group')
9+
expect(wrapper.classes().length).toBe(1)
10+
expect(wrapper.attributes('role')).toBeDefined()
11+
expect(wrapper.attributes('role')).toBe('group')
12+
expect(wrapper.text()).toBe('')
13+
})
1114

12-
expect($refs.basic).toHaveClass('btn-group')
15+
it('should render default slot', async () => {
16+
const wrapper = mount(ButtonGroup, {
17+
slots: {
18+
default: '<span>foobar</span>'
19+
}
20+
})
21+
expect(wrapper.is('div')).toBe(true)
22+
expect(wrapper.classes()).toContain('btn-group')
23+
expect(wrapper.classes().length).toBe(1)
24+
expect(wrapper.attributes('role')).toBeDefined()
25+
expect(wrapper.attributes('role')).toBe('group')
26+
expect(wrapper.find('span').exists()).toBe(true)
27+
expect(wrapper.text()).toBe('foobar')
1328
})
1429

1530
it('should apply vertical class', async () => {
16-
const {
17-
app: { $refs }
18-
} = window
19-
20-
expect($refs.vertical).toHaveClass('btn-group-vertical')
31+
const wrapper = mount(ButtonGroup, {
32+
propsData: {
33+
vertical: true
34+
}
35+
})
36+
expect(wrapper.is('div')).toBe(true)
37+
expect(wrapper.classes()).toContain('btn-group-vertical')
38+
expect(wrapper.classes()).not.toContain('btn-group')
39+
expect(wrapper.classes().length).toBe(1)
2140
})
2241

2342
it('should apply size class', async () => {
24-
const {
25-
app: { $refs }
26-
} = window
43+
const wrapper = mount(ButtonGroup, {
44+
propsData: {
45+
size: 'sm'
46+
}
47+
})
48+
expect(wrapper.is('div')).toBe(true)
49+
expect(wrapper.classes()).toContain('btn-group')
50+
expect(wrapper.classes()).toContain('btn-group-sm')
51+
expect(wrapper.classes().length).toBe(2)
52+
})
53+
54+
it('should apply size class when vertical', async () => {
55+
const wrapper = mount(ButtonGroup, {
56+
propsData: {
57+
size: 'sm',
58+
vertical: true
59+
}
60+
})
61+
expect(wrapper.is('div')).toBe(true)
62+
expect(wrapper.classes()).toContain('btn-group-sm')
63+
expect(wrapper.classes()).toContain('btn-group-vertical')
64+
expect(wrapper.classes()).not.toContain('btn-group')
65+
expect(wrapper.classes().length).toBe(2)
66+
})
2767

28-
expect($refs.size).toHaveClass('btn-group-sm')
68+
it('has custom role when aria-role prop set', async () => {
69+
const wrapper = mount(ButtonGroup, {
70+
propsData: {
71+
ariaRole: 'foobar'
72+
}
73+
})
74+
expect(wrapper.is('div')).toBe(true)
75+
expect(wrapper.classes()).toContain('btn-group')
76+
expect(wrapper.classes().length).toBe(1)
77+
expect(wrapper.attributes('role')).toBeDefined()
78+
expect(wrapper.attributes('role')).toBe('foobar')
2979
})
3080
})

src/components/button-group/fixtures/button-group.html

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/components/button-group/fixtures/button-group.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)