-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
select.test.jsx
27 lines (25 loc) · 984 Bytes
/
select.test.jsx
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
import { render } from '@testing-library/react'
import { expect, test } from 'vitest'
import Select from '@/Components/select'
const options = [
{ label: 'A', value: 'a' },
{ label: 'B', value: 'b' },
]
describe('SelectBoxのテスト', () => {
test('SelectBoxにname属性が設定されているかどうか', () => {
const { getByRole } = render(
<Select name='optionstest' defaultVal={options[0].value} options={options} />,
)
const selectElement = getByRole('combobox')
expect(selectElement).toHaveAttribute('name', 'optionstest')
})
test('defaultValueが正しく設定されていることを確認する', () => {
const defaultVal = 'a'
const { getByRole } = render(
<Select name='optionstest' options={options} defaultVal={options[0].value} />,
)
const selectElement = getByRole('combobox')
const selectedOptionValue = selectElement.selectedOptions[0].value
expect(selectedOptionValue).toBe(defaultVal)
})
})