-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
/
VChip.spec.ts
169 lines (135 loc) Β· 3.75 KB
/
VChip.spec.ts
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Libraries
import Vue from 'vue'
// Plugins
import Router from 'vue-router'
// Components
import VChip from '../VChip'
// Utilities
import {
createLocalVue,
mount,
Wrapper,
} from '@vue/test-utils'
describe('VChip.ts', () => {
let mountFunction: (options?: object) => Wrapper<Vue>
let router: Router
let localVue: typeof Vue
beforeEach(() => {
router = new Router()
localVue = createLocalVue()
localVue.use(Router)
mountFunction = (options = {}) => {
return mount(VChip, {
// https://github.com/vuejs/vue-test-utils/issues/1130
sync: false,
localVue,
router,
mocks: {
$vuetify: {
lang: {
t: (val: string) => val,
},
},
},
...options,
})
}
})
it('should have a v-chip class', () => {
const wrapper = mountFunction()
expect(wrapper.classes()).toContain('v-chip')
expect(wrapper.html()).toMatchSnapshot()
})
it('should be removable', () => {
const wrapper = mountFunction({
propsData: { close: true },
})
const close = wrapper.find('.v-chip__close')
const input = jest.fn(value => wrapper.setProps({ value }))
wrapper.vm.$on('click:close', input)
expect(wrapper.html()).toMatchSnapshot()
close.trigger('click')
expect(input).toHaveBeenCalled()
})
it('should render a colored chip', () => {
const wrapper = mountFunction({
propsData: {
color: 'blue',
textColor: 'green',
},
})
expect(wrapper.element.classList).toContain('blue')
expect(wrapper.element.classList).toContain('green--text')
})
it('should render a disabled chip', async () => {
const wrapper = mountFunction({
propsData: {
disabled: true,
},
})
expect(wrapper.element.classList).toContain('v-chip--disabled')
wrapper.setProps({
close: true,
})
await wrapper.vm.$nextTick()
expect(wrapper.findAll('.v-chip__close')).toHaveLength(1)
})
it('should render a colored outline chip', () => {
const wrapper = mountFunction({
propsData: {
outlined: true,
color: 'blue',
},
})
expect(wrapper.element.classList).toContain('blue')
expect(wrapper.element.classList).toContain('blue--text')
})
it('should render a colored outline chip with text color', () => {
const wrapper = mountFunction({
propsData: {
outlined: true,
color: 'blue',
textColor: 'green',
},
})
expect(wrapper.element.classList).toContain('blue')
expect(wrapper.element.classList).toContain('green--text')
})
it('should render a chip with filter', () => {
const wrapper = mountFunction({
propsData: {
filter: true,
inputValue: true,
},
})
expect(wrapper.findAll('.v-chip__filter')).toHaveLength(1)
})
it('should call toggle event when used in the group', () => {
const register = jest.fn()
const unregister = jest.fn()
const toggle = jest.fn()
const wrapper = mountFunction({
provide: {
chipGroup: { register, unregister },
},
methods: { toggle },
})
wrapper.trigger('click')
expect(toggle).toHaveBeenCalled()
})
it('should conditionally show based on active prop', async () => {
const active = jest.fn()
const wrapper = mountFunction({
propsData: { close: true },
})
const close = wrapper.find('.v-chip__close')
wrapper.vm.$on('update:active', active)
expect(wrapper.isVisible()).toBe(true)
close.trigger('click')
expect(active).toHaveBeenCalledTimes(1)
// Simulate active.sync behavior
wrapper.setProps({ active: false })
await wrapper.vm.$nextTick()
expect(wrapper.isVisible()).toBe(false)
})
})