1
+
import { mount } from '@vue/test-utils'
2
+
import { BFormTag } from './form-tag'
3
+
4
+
describe('form-tag', () => {
5
+
it('has expected structure', async () => {
6
+
const wrapper = mount(BFormTag, {
7
+
propsData: {
8
+
title: 'foobar'
9
+
}
10
+
})
11
+
12
+
expect(wrapper.is('span')).toBe(true)
13
+
14
+
expect(wrapper.classes()).toContain('b-form-tag')
15
+
expect(wrapper.classes()).toContain('badge')
16
+
expect(wrapper.classes()).toContain('badge-secondary')
17
+
expect(wrapper.attributes('title')).toBe('foobar')
18
+
expect(wrapper.text()).toContain('foobar')
19
+
20
+
const $btn = wrapper.find('button')
21
+
expect($btn.exists()).toBe(true)
22
+
expect($btn.classes()).toContain('close')
23
+
expect($btn.classes()).toContain('b-form-tag-remove')
24
+
expect($btn.attributes('aria-label')).toBe('Remove tag')
25
+
26
+
wrapper.destroy()
27
+
})
28
+
29
+
it('renders custom root element', async () => {
30
+
const wrapper = mount(BFormTag, {
31
+
propsData: {
32
+
title: 'foobar',
33
+
tag: 'li'
34
+
}
35
+
})
36
+
37
+
expect(wrapper.is('li')).toBe(true)
38
+
39
+
expect(wrapper.classes()).toContain('b-form-tag')
40
+
expect(wrapper.classes()).toContain('badge')
41
+
expect(wrapper.classes()).toContain('badge-secondary')
42
+
expect(wrapper.attributes('title')).toBe('foobar')
43
+
expect(wrapper.text()).toContain('foobar')
44
+
45
+
const $btn = wrapper.find('button')
46
+
expect($btn.exists()).toBe(true)
47
+
expect($btn.classes()).toContain('close')
48
+
expect($btn.classes()).toContain('b-form-tag-remove')
49
+
expect($btn.attributes('aria-label')).toBe('Remove tag')
50
+
51
+
wrapper.destroy()
52
+
})
53
+
54
+
it('renders default slot', async () => {
55
+
const wrapper = mount(BFormTag, {
56
+
propsData: {
57
+
title: 'foo'
58
+
},
59
+
slots: {
60
+
default: 'bar'
61
+
}
62
+
})
63
+
64
+
expect(wrapper.is('span')).toBe(true)
65
+
66
+
expect(wrapper.classes()).toContain('b-form-tag')
67
+
expect(wrapper.classes()).toContain('badge')
68
+
expect(wrapper.classes()).toContain('badge-secondary')
69
+
expect(wrapper.attributes('title')).toBe('foo')
70
+
expect(wrapper.text()).toContain('bar')
71
+
expect(wrapper.text()).not.toContain('foo')
72
+
73
+
const $btn = wrapper.find('button')
74
+
expect($btn.exists()).toBe(true)
75
+
expect($btn.classes()).toContain('close')
76
+
expect($btn.classes()).toContain('b-form-tag-remove')
77
+
expect($btn.attributes('aria-label')).toBe('Remove tag')
78
+
79
+
wrapper.destroy()
80
+
})
81
+
82
+
it('emits remove event when button clicked', async () => {
83
+
const wrapper = mount(BFormTag, {
84
+
propsData: {
85
+
title: 'foobar'
86
+
}
87
+
})
88
+
89
+
expect(wrapper.is('span')).toBe(true)
90
+
91
+
expect(wrapper.classes()).toContain('b-form-tag')
92
+
expect(wrapper.classes()).toContain('badge')
93
+
expect(wrapper.classes()).toContain('badge-secondary')
94
+
expect(wrapper.attributes('title')).toBe('foobar')
95
+
expect(wrapper.text()).toContain('foobar')
96
+
97
+
const $btn = wrapper.find('button')
98
+
expect($btn.exists()).toBe(true)
99
+
expect($btn.classes()).toContain('close')
100
+
expect($btn.classes()).toContain('b-form-tag-remove')
101
+
expect($btn.attributes('aria-label')).toBe('Remove tag')
102
+
103
+
expect(wrapper.emitted('remove')).not.toBeDefined()
104
+
105
+
$btn.trigger('click')
106
+
107
+
expect(wrapper.emitted('remove')).toBeDefined()
108
+
expect(wrapper.emitted('remove').length).toBe(1)
109
+
110
+
wrapper.destroy()
111
+
})
112
+
})
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4