1
1
import { mount, createLocalVue as CreateLocalVue } from '@vue/test-utils'
2
2
import { BIconPerson } from '../../icons/icons'
3
3
import { BAvatar } from './avatar'
4
+
import { waitNT } from '../../../tests/utils'
4
5
5
6
describe('avatar', () => {
6
7
it('should have expected default structure', async () => {
7
8
const wrapper = mount(BAvatar)
9
+
expect(wrapper.isVueInstance()).toBe(true)
8
10
expect(wrapper.is('span')).toBe(true)
9
11
expect(wrapper.classes()).toContain('b-avatar')
10
12
expect(wrapper.classes()).toContain('badge-secondary')
11
13
expect(wrapper.classes()).not.toContain('disabled')
12
14
expect(wrapper.attributes('href')).not.toBeDefined()
13
15
expect(wrapper.attributes('type')).not.toBeDefined()
16
+
wrapper.destroy()
14
17
})
15
18
16
19
it('should have expected structure when prop `button` set', async () => {
@@ -19,6 +22,7 @@ describe('avatar', () => {
19
22
button: true
20
23
}
21
24
})
25
+
expect(wrapper.isVueInstance()).toBe(true)
22
26
expect(wrapper.is('button')).toBe(true)
23
27
expect(wrapper.classes()).toContain('b-avatar')
24
28
expect(wrapper.classes()).toContain('btn-secondary')
@@ -29,6 +33,17 @@ describe('avatar', () => {
29
33
expect(wrapper.text()).toEqual('')
30
34
expect(wrapper.find('.b-icon').exists()).toBe(true)
31
35
expect(wrapper.find('img').exists()).toBe(false)
36
+
37
+
expect(wrapper.emitted('click')).toBeUndefined()
38
+
39
+
wrapper.trigger('click')
40
+
await waitNT(wrapper.vm)
41
+
42
+
expect(wrapper.emitted('click')).not.toBeUndefined()
43
+
expect(wrapper.emitted('click').length).toBe(1)
44
+
expect(wrapper.emitted('click')[0][0]).toBeInstanceOf(Event)
45
+
46
+
wrapper.destroy()
32
47
})
33
48
34
49
it('should have expected structure when prop `href` set', async () => {
@@ -37,6 +52,7 @@ describe('avatar', () => {
37
52
href: '#foo'
38
53
}
39
54
})
55
+
expect(wrapper.isVueInstance()).toBe(true)
40
56
expect(wrapper.is('a')).toBe(true)
41
57
expect(wrapper.classes()).toContain('b-avatar')
42
58
expect(wrapper.classes()).toContain('badge-secondary')
@@ -48,6 +64,17 @@ describe('avatar', () => {
48
64
expect(wrapper.text()).toEqual('')
49
65
expect(wrapper.find('.b-icon').exists()).toBe(true)
50
66
expect(wrapper.find('img').exists()).toBe(false)
67
+
68
+
expect(wrapper.emitted('click')).toBeUndefined()
69
+
70
+
wrapper.trigger('click')
71
+
await waitNT(wrapper.vm)
72
+
73
+
expect(wrapper.emitted('click')).not.toBeUndefined()
74
+
expect(wrapper.emitted('click').length).toBe(1)
75
+
expect(wrapper.emitted('click')[0][0]).toBeInstanceOf(Event)
76
+
77
+
wrapper.destroy()
51
78
})
52
79
53
80
it('should have expected structure when prop `text` set', async () => {
@@ -56,6 +83,7 @@ describe('avatar', () => {
56
83
text: 'BV'
57
84
}
58
85
})
86
+
expect(wrapper.isVueInstance()).toBe(true)
59
87
expect(wrapper.is('span')).toBe(true)
60
88
expect(wrapper.classes()).toContain('b-avatar')
61
89
expect(wrapper.classes()).toContain('badge-secondary')
@@ -65,6 +93,7 @@ describe('avatar', () => {
65
93
expect(wrapper.text()).toContain('BV')
66
94
expect(wrapper.find('.b-icon').exists()).toBe(false)
67
95
expect(wrapper.find('img').exists()).toBe(false)
96
+
wrapper.destroy()
68
97
})
69
98
70
99
it('should have expected structure when default slot used', async () => {
@@ -76,6 +105,7 @@ describe('avatar', () => {
76
105
default: 'BAR'
77
106
}
78
107
})
108
+
expect(wrapper.isVueInstance()).toBe(true)
79
109
expect(wrapper.is('span')).toBe(true)
80
110
expect(wrapper.classes()).toContain('b-avatar')
81
111
expect(wrapper.classes()).toContain('badge-secondary')
@@ -86,14 +116,17 @@ describe('avatar', () => {
86
116
expect(wrapper.text()).not.toContain('FOO')
87
117
expect(wrapper.find('.b-icon').exists()).toBe(false)
88
118
expect(wrapper.find('img').exists()).toBe(false)
119
+
wrapper.destroy()
89
120
})
90
121
91
122
it('should have expected structure when prop `src` set', async () => {
92
123
const wrapper = mount(BAvatar, {
93
124
propsData: {
94
-
src: '/foo/bar'
125
+
src: '/foo/bar',
126
+
text: 'BV'
95
127
}
96
128
})
129
+
expect(wrapper.isVueInstance()).toBe(true)
97
130
expect(wrapper.is('span')).toBe(true)
98
131
expect(wrapper.classes()).toContain('b-avatar')
99
132
expect(wrapper.classes()).toContain('badge-secondary')
@@ -104,9 +137,31 @@ describe('avatar', () => {
104
137
expect(wrapper.find('.b-icon').exists()).toBe(false)
105
138
expect(wrapper.find('img').exists()).toBe(true)
106
139
expect(wrapper.find('img').attributes('src')).toEqual('/foo/bar')
140
+
expect(wrapper.text()).not.toContain('BV')
141
+
142
+
wrapper.setProps({
143
+
src: '/foo/baz'
144
+
})
145
+
await waitNT(wrapper.vm)
146
+
147
+
expect(wrapper.find('img').exists()).toBe(true)
148
+
expect(wrapper.find('img').attributes('src')).toEqual('/foo/baz')
149
+
expect(wrapper.text()).not.toContain('BV')
150
+
expect(wrapper.emitted('img-error')).not.toBeDefined()
151
+
expect(wrapper.text()).not.toContain('BV')
152
+
153
+
// Fake an image error
154
+
wrapper.find('img').trigger('error')
155
+
await waitNT(wrapper.vm)
156
+
expect(wrapper.emitted('img-error')).toBeDefined()
157
+
expect(wrapper.emitted('img-error').length).toBe(1)
158
+
expect(wrapper.find('img').exists()).toBe(false)
159
+
expect(wrapper.text()).toContain('BV')
160
+
161
+
wrapper.destroy()
107
162
})
108
163
109
-
it('should have expected structure when prop `src` set', async () => {
164
+
it('should have expected structure when prop `icon` set', async () => {
110
165
const localVue = new CreateLocalVue()
111
166
localVue.component('BIconPerson', BIconPerson)
112
167
const wrapper = mount(BAvatar, {
@@ -115,6 +170,7 @@ describe('avatar', () => {
115
170
icon: 'person'
116
171
}
117
172
})
173
+
expect(wrapper.isVueInstance()).toBe(true)
118
174
expect(wrapper.is('span')).toBe(true)
119
175
expect(wrapper.classes()).toContain('b-avatar')
120
176
expect(wrapper.classes()).toContain('badge-secondary')
@@ -125,31 +181,40 @@ describe('avatar', () => {
125
181
const $icon = wrapper.find('.b-icon')
126
182
expect($icon.exists()).toBe(true)
127
183
expect($icon.classes()).toContain('bi-person')
184
+
wrapper.destroy()
128
185
})
129
186
130
187
it('`size` prop should work as expected', async () => {
131
188
const wrapper1 = mount(BAvatar)
132
189
expect(wrapper1.attributes('style')).toEqual('width: 2.5em; height: 2.5em;')
190
+
wrapper1.destroy()
133
191
134
192
const wrapper2 = mount(BAvatar, { propsData: { size: 'sm' } })
135
193
expect(wrapper2.attributes('style')).toEqual('width: 1.5em; height: 1.5em;')
194
+
wrapper2.destroy()
136
195
137
196
const wrapper3 = mount(BAvatar, { propsData: { size: 'md' } })
138
197
expect(wrapper3.attributes('style')).toEqual('width: 2.5em; height: 2.5em;')
198
+
wrapper3.destroy()
139
199
140
200
const wrapper4 = mount(BAvatar, { propsData: { size: 'lg' } })
141
201
expect(wrapper4.attributes('style')).toEqual('width: 3.5em; height: 3.5em;')
202
+
wrapper4.destroy()
142
203
143
204
const wrapper5 = mount(BAvatar, { propsData: { size: 20 } })
144
205
expect(wrapper5.attributes('style')).toEqual('width: 20px; height: 20px;')
206
+
wrapper5.destroy()
145
207
146
208
const wrapper6 = mount(BAvatar, { propsData: { size: '24.5' } })
147
209
expect(wrapper6.attributes('style')).toEqual('width: 24.5px; height: 24.5px;')
210
+
wrapper6.destroy()
148
211
149
212
const wrapper7 = mount(BAvatar, { propsData: { size: '5em' } })
150
213
expect(wrapper7.attributes('style')).toEqual('width: 5em; height: 5em;')
214
+
wrapper7.destroy()
151
215
152
216
const wrapper8 = mount(BAvatar, { propsData: { size: '36px' } })
153
217
expect(wrapper8.attributes('style')).toEqual('width: 36px; height: 36px;')
218
+
wrapper8.destroy()
154
219
})
155
220
})
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