Skip to content

Commit e5d7f80

Browse files
committed
test: added tests
1 parent 97b83c8 commit e5d7f80

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

tests/searchInput.spec.ts

+50-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mount } from '@vue/test-utils'
22
import SearchInput from '@/SearchInput.vue'
33
import { fieldType } from '@/SearchInput.types'
4+
import { nextTick } from 'vue'
45

56
const createWrapper = (opts?: Record<string, unknown>) => {
67
return mount(SearchInput, opts)
@@ -26,7 +27,7 @@ describe('SearchInput.vue', () => {
2627
it('should render a search icon', async () => {
2728
const wrapper = createWrapper()
2829

29-
const div = await wrapper.find('div.search-icon search')
30+
const div = await wrapper.find('div.search-icon.search')
3031

3132
expect(div).toBeTruthy()
3233
})
@@ -51,4 +52,52 @@ describe('SearchInput.vue', () => {
5152

5253
expect(onClick).toHaveBeenCalled()
5354
})
55+
56+
it('sets the value', async () => {
57+
const wrapper = createWrapper()
58+
const input = wrapper.find('input')
59+
60+
await input.setValue('test_value')
61+
62+
expect(input.element.value).toBe('test_value')
63+
})
64+
65+
it('emits the updated value', async () => {
66+
const wrapper = createWrapper()
67+
const input = wrapper.find('input')
68+
69+
await input.setValue('test_value')
70+
71+
expect(wrapper.emitted()['update:modelValue'][0]).toEqual(['test_value'])
72+
})
73+
74+
it('clears the value when the clear icon is clicked', async () => {
75+
const wrapper = createWrapper({
76+
props: {
77+
modelValue: 'test'
78+
}
79+
})
80+
81+
const clearIcon = await wrapper.find('div.search-icon.clear')
82+
83+
await clearIcon.trigger('mousedown')
84+
85+
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([''])
86+
})
87+
88+
it('esc key clears the value', async () => {
89+
const wrapper = createWrapper({
90+
props: {
91+
modelValue: 'test'
92+
}
93+
})
94+
95+
const input = wrapper.find('input')
96+
97+
await input.trigger('keydown', {
98+
key: 'Escape'
99+
})
100+
101+
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([''])
102+
})
54103
})

0 commit comments

Comments
 (0)