breadcrumb-link.spec.js
2.96 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { mount } from '@vue/test-utils'
import { BBreadcrumbLink } from './breadcrumb-link'
describe('breadcrumb-link', () => {
it('has default classes and structure', async () => {
const wrapper = mount(BBreadcrumbLink)
expect(wrapper.element.tagName).toBe('A')
expect(wrapper.attributes('href')).toBeDefined()
expect(wrapper.attributes('href')).toBe('#')
expect(wrapper.classes().length).toBe(0)
expect(wrapper.attributes('aria-current')).toBeUndefined()
expect(wrapper.text()).toBe('')
wrapper.destroy()
})
it('has content from default slot', async () => {
const wrapper = mount(BBreadcrumbLink, {
slots: {
default: 'foobar'
}
})
expect(wrapper.text()).toBe('foobar')
wrapper.destroy()
})
it('has content from text prop', async () => {
const wrapper = mount(BBreadcrumbLink, {
propsData: {
text: 'foobar'
}
})
expect(wrapper.text()).toBe('foobar')
wrapper.destroy()
})
it('has content from html prop', async () => {
const wrapper = mount(BBreadcrumbLink, {
propsData: {
html: 'foobar'
}
})
expect(wrapper.text()).toBe('foobar')
wrapper.destroy()
})
it('has attribute aria-current when active', async () => {
const wrapper = mount(BBreadcrumbLink, {
propsData: {
active: true
}
})
expect(wrapper.element.tagName).toBe('SPAN')
expect(wrapper.attributes('href')).toBeUndefined()
expect(wrapper.attributes('aria-current')).toBe('location')
expect(wrapper.classes().length).toBe(0)
wrapper.destroy()
})
it('has attribute aria-current with custom value when active', async () => {
const wrapper = mount(BBreadcrumbLink, {
propsData: {
active: true,
ariaCurrent: 'foobar'
}
})
expect(wrapper.element.tagName).toBe('SPAN')
expect(wrapper.attributes('aria-current')).toBe('foobar')
expect(wrapper.attributes('href')).toBeUndefined()
expect(wrapper.classes().length).toBe(0)
wrapper.destroy()
})
it('renders link when href is set', async () => {
const wrapper = mount(BBreadcrumbLink, {
propsData: {
href: '/foo/bar'
}
})
expect(wrapper.element.tagName).toBe('A')
expect(wrapper.attributes('href')).toBeDefined()
expect(wrapper.attributes('href')).toBe('/foo/bar')
expect(wrapper.attributes('aria-current')).toBeUndefined()
expect(wrapper.classes().length).toBe(0)
wrapper.destroy()
})
it('does not render a link when href is set and active', async () => {
const wrapper = mount(BBreadcrumbLink, {
propsData: {
active: true,
href: '/foo/bar'
}
})
expect(wrapper.element.tagName).toBe('SPAN')
expect(wrapper.attributes('href')).toBeUndefined()
expect(wrapper.attributes('aria-current')).toBeDefined()
expect(wrapper.attributes('aria-current')).toBe('location')
expect(wrapper.classes().length).toBe(0)
wrapper.destroy()
})
})