-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathQInput.test.js
More file actions
49 lines (42 loc) · 1.49 KB
/
Copy pathQInput.test.js
File metadata and controls
49 lines (42 loc) · 1.49 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
import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import QInput from './QInput.js'
describe('[QInput API]', () => {
describe('[Accessibility]', () => {
test('exposes error state and message relationship on the native control', () => {
const wrapper = mount(QInput, {
props: {
modelValue: '',
label: 'Email',
error: true,
errorMessage: 'Email is required'
}
})
const input = wrapper.get('input')
const message = wrapper.get('.q-field__messages')
const messageId = message.attributes('id')
expect(message.text()).toBe('Email is required')
expect(messageId).toBeTruthy()
expect(input.attributes('aria-invalid')).toBe('true')
expect(input.attributes('aria-errormessage')).toBe(messageId)
expect(input.attributes('aria-describedby')?.split(' ')).toContain(
messageId
)
})
test('preserves existing aria-describedby values when adding the error message', () => {
const wrapper = mount(QInput, {
attrs: {
'aria-describedby': 'external-help'
},
props: {
modelValue: '',
error: true,
errorMessage: 'Required'
}
})
const describedBy = wrapper.get('input').attributes('aria-describedby')
const messageId = wrapper.get('.q-field__messages').attributes('id')
expect(describedBy?.split(' ')).toEqual(['external-help', messageId])
})
})
})