@@ -2,20 +2,23 @@ import { render, fireEvent } from '@testing-library/vue'
22import '@testing-library/jest-dom/extend-expect'
33import Form from './components/Form'
44
5+ // In this test we showcase several ways of targetting DOM elements.
6+ // However, `getByLabelText` should be your top preference when handling
7+ // form elements.
8+ // Read 'What queries should I use?' for additional context:
9+ // https://testing-library.com/docs/guide-which-query
510test ( 'Review form submits' , async ( ) => {
611 const fakeReview = {
712 title : 'An Awesome Movie' ,
813 review : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' ,
914 rating : '3' ,
10- genre : 'Action' ,
1115 recommend : true
1216 }
1317
1418 const {
1519 getByLabelText,
1620 getByText,
1721 getByRole,
18- getByDisplayValue,
1922 getByPlaceholderText,
2023 emitted
2124 } = render ( Form )
@@ -25,28 +28,30 @@ test('Review form submits', async () => {
2528 // Initially the submit button should be disabled
2629 expect ( submitButton ) . toBeDisabled ( )
2730
28- // In this test we showcase several ways of targetting DOM elements.
29- // However, `getByLabelText` should be your top preference when handling
30- // form elements.
31- // Read 'What queries should I use?' for additional context:
32- // https://testing-library.com/docs/guide-which-query
33-
3431 const titleInput = getByLabelText ( / t i t l e o f t h e m o v i e / i)
3532 await fireEvent . update ( titleInput , fakeReview . title )
3633
3734 const reviewTextarea = getByPlaceholderText ( 'Write an awesome review' )
3835 await fireEvent . update ( reviewTextarea , fakeReview . review )
3936
37+ // Rating Radio buttons
38+ const initiallySelectedInput = getByLabelText ( 'Awful' )
4039 const ratingSelect = getByLabelText ( 'Wonderful' )
41- await fireEvent . update ( ratingSelect , fakeReview . rating )
4240
43- // Get the Select element by using the initially displayed value.
44- const genreSelect = getByDisplayValue ( 'Comedy' )
45- await fireEvent . update ( genreSelect , fakeReview . genre )
41+ expect ( initiallySelectedInput . checked ) . toBe ( true )
42+ expect ( ratingSelect . checked ) . toBe ( false )
43+
44+ await fireEvent . update ( ratingSelect )
45+
46+ expect ( ratingSelect . checked ) . toBe ( true )
47+ expect ( initiallySelectedInput . checked ) . toBe ( false )
4648
4749 // Get the Input element by its implicit ARIA role.
4850 const recommendInput = getByRole ( 'checkbox' )
49- await fireEvent . update ( recommendInput , fakeReview . recommend )
51+
52+ expect ( recommendInput . checked ) . toBe ( false )
53+ await fireEvent . update ( recommendInput )
54+ expect ( recommendInput . checked ) . toBe ( true )
5055
5156 // NOTE: in jsdom, it's not possible to trigger a form submission
5257 // by clicking on the submit button. This is really unfortunate.
0 commit comments