@@ -2,29 +2,26 @@ import { render, fireEvent } from '@testing-library/vue'
22import '@testing-library/jest-dom/extend-expect'
33import Select from './components/Select'
44
5- // There are several ways to interact with a Select component.
5+ // In this test file we showcase several ways to interact with a Select element
66test ( 'Select component' , async ( ) => {
7+ let optionElement
78 const { getByDisplayValue, getByText } = render ( Select )
89
9- // Get the Select element by using the initially displayed value.
10+ // Get the Select element by using the initially displayed value
1011 const select = getByDisplayValue ( 'Tyrannosaurus' )
11-
12- // Assert initial value
1312 expect ( select . value ) . toBe ( 'dino1' )
1413
15- // Update it by manually sending an option value
14+ // Update it by manually sending a valid option value
1615 await fireEvent . update ( select , 'dino2' )
1716 expect ( select . value ) . toBe ( 'dino2' )
1817
19- // We can also get the option value from the element itself
20- await fireEvent . update ( select , getByText ( 'Tyrannosaurus' ) . value )
21- expect ( select . value ) . toBe ( 'dino1' )
22-
2318 // We can trigger an update event by directly getting the <option> element
24- await fireEvent . update ( getByText ( 'Deinonychus' ) )
19+ optionElement = getByText ( 'Deinonychus' )
20+ await fireEvent . update ( optionElement )
2521 expect ( select . value ) . toBe ( 'dino3' )
2622
2723 // ...even if option is within an <optgroup>
28- await fireEvent . update ( getByText ( 'Diplodocus' ) )
24+ optionElement = getByText ( 'Diplodocus' )
25+ await fireEvent . update ( optionElement )
2926 expect ( select . value ) . toBe ( 'dino4' )
3027} )
0 commit comments