🌐 AI搜索 & 代理 主页
Skip to content

Commit c6e9874

Browse files
committed
add test cases
1 parent 5bb6054 commit c6e9874

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

src/components/avatar/avatar.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,34 @@ describe('avatar', () => {
317317

318318
wrapper2.destroy()
319319
})
320+
321+
it('should render `alt` attribute if `alt` prop is empty string', async () => {
322+
const wrapper = mount(BAvatar, {
323+
propsData: {
324+
src: '/foo/bar',
325+
alt: ''
326+
}
327+
})
328+
expect(wrapper.vm).toBeDefined()
329+
expect(wrapper.find('img').exists()).toBe(true)
330+
expect(wrapper.find('img').attributes('src')).toEqual('/foo/bar')
331+
expect(wrapper.find('img').attributes('alt')).toEqual('')
332+
333+
wrapper.destroy()
334+
})
335+
336+
it('should not render `alt` attribute if `alt` prop is null', async () => {
337+
const wrapper = mount(BAvatar, {
338+
propsData: {
339+
src: '/foo/bar',
340+
alt: null
341+
}
342+
})
343+
expect(wrapper.vm).toBeDefined()
344+
expect(wrapper.find('img').exists()).toBe(true)
345+
expect(wrapper.find('img').attributes('src')).toEqual('/foo/bar')
346+
expect(wrapper.find('img').attributes('alt')).not.toBeDefined()
347+
348+
wrapper.destroy()
349+
})
320350
})

src/components/card/card-img-lazy.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ describe('card-image', () => {
154154
wrapper.destroy()
155155
})
156156

157+
it('has attribute alt when prop `alt` empty', async () => {
158+
const wrapper = mount(BCardImgLazy, {
159+
context: {
160+
props: {
161+
src: 'https://picsum.photos/600/300/?image=25',
162+
alt: ''
163+
}
164+
}
165+
})
166+
167+
expect(wrapper.attributes('alt')).toBeDefined()
168+
expect(wrapper.attributes('alt')).toBe('')
169+
170+
wrapper.destroy()
171+
})
172+
157173
it('has attribute width when prop width set', async () => {
158174
const wrapper = mount(BCardImgLazy, {
159175
context: {

src/components/card/card-img.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ describe('card-image', () => {
158158
wrapper.destroy()
159159
})
160160

161+
it('has attribute alt when prop `alt` empty', async () => {
162+
const wrapper = mount(BCardImg, {
163+
context: {
164+
props: {
165+
src: 'https://picsum.photos/600/300/?image=25',
166+
alt: ''
167+
}
168+
}
169+
})
170+
171+
expect(wrapper.attributes('alt')).toBeDefined()
172+
expect(wrapper.attributes('alt')).toBe('')
173+
174+
wrapper.destroy()
175+
})
176+
161177
it('has attribute width when prop width set', async () => {
162178
const wrapper = mount(BCardImg, {
163179
context: {

src/components/image/img.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ describe('img', () => {
3030
wrapper.destroy()
3131
})
3232

33+
it('default does not have attributes alt, width, or height', async () => {
34+
const wrapper = mount(BImg, {
35+
context: {
36+
props: {
37+
src: 'https://picsum.photos/600/300/?image=25'
38+
}
39+
}
40+
})
41+
42+
expect(wrapper.attributes('alt')).not.toBeDefined()
43+
expect(wrapper.attributes('width')).not.toBeDefined()
44+
expect(wrapper.attributes('height')).not.toBeDefined()
45+
46+
wrapper.destroy()
47+
})
48+
3349
it('should have class "img-fluid" when prop fluid set', async () => {
3450
const wrapper = mount(BImg, {
3551
propsData: {
@@ -223,4 +239,17 @@ describe('img', () => {
223239

224240
wrapper.destroy()
225241
})
242+
243+
it('should have alt attribute when `alt` prop is empty', async () => {
244+
const wrapper = mount(BImg, {
245+
propsData: {
246+
alt: ''
247+
}
248+
})
249+
250+
expect(wrapper.attributes('alt')).toBeDefined()
251+
expect(wrapper.attributes('alt')).toEqual('')
252+
253+
wrapper.destroy()
254+
})
226255
})

0 commit comments

Comments
 (0)