-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathselect.js
27 lines (22 loc) · 979 Bytes
/
select.js
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, fireEvent} from '..'
import '@testing-library/jest-dom'
import Select from './components/Select'
// In this test file we showcase several ways to interact with a Select element.
test('Select component', async () => {
let optionElement
const {getByDisplayValue, getByText} = render(Select)
// Get the Select element by using the initially displayed value.
const select = getByDisplayValue('Tyrannosaurus')
expect(select).toHaveValue('dino1')
// Update it by manually sending a valid option value.
await fireEvent.update(select, 'dino2')
expect(select).toHaveValue('dino2')
// We can trigger an update event by directly getting the <option> element.
optionElement = getByText('Deinonychus')
await fireEvent.update(optionElement)
expect(select).toHaveValue('dino3')
// ...even if option is within an <optgroup>.
optionElement = getByText('Diplodocus')
await fireEvent.update(optionElement)
expect(select).toHaveValue('dino4')
})