Skip to content

Commit 2312e18

Browse files
authored
test: remove await from userEvent usage (#182)
* test: remove await from userEvent usage * test: fix test failure with waitFor
1 parent 3dbb1c2 commit 2312e18

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/__tests__/user-event.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import '@testing-library/jest-dom'
2-
import {render} from '@testing-library/vue'
2+
import {render, waitFor} from '@testing-library/vue'
33
import userEvent from '@testing-library/user-event'
44
import Form from './components/Form'
55
import Select from './components/Select'
@@ -24,49 +24,49 @@ test('User events in a form', async () => {
2424
expect(submitButton).toBeDisabled()
2525

2626
const titleInput = getByLabelText(/title of the movie/i)
27-
await userEvent.type(titleInput, fakeReview.title)
27+
userEvent.type(titleInput, fakeReview.title)
2828
expect(titleInput.value).toEqual(fakeReview.title)
2929

3030
const textArea = getByLabelText(/Your review/i)
31-
await userEvent.type(textArea, 'The t-rex went insane!')
31+
userEvent.type(textArea, 'The t-rex went insane!')
3232
expect(textArea.value).toEqual('The t-rex went insane!')
3333

34-
await userEvent.clear(textArea)
34+
userEvent.clear(textArea)
3535
expect(textArea.value).toEqual('')
36-
await userEvent.type(textArea, fakeReview.review)
36+
userEvent.type(textArea, fakeReview.review)
3737
expect(textArea.value).toEqual(fakeReview.review)
3838

3939
const initialSelectedRating = getByLabelText(/Awful/i)
4040
const wonderfulRadioInput = getByLabelText(/Wonderful/i)
4141
expect(initialSelectedRating).toBeChecked()
4242
expect(wonderfulRadioInput).not.toBeChecked()
4343

44-
await userEvent.click(wonderfulRadioInput)
44+
userEvent.click(wonderfulRadioInput)
4545
expect(wonderfulRadioInput).toBeChecked()
46-
expect(initialSelectedRating).not.toBeChecked()
46+
await waitFor(() => expect(initialSelectedRating).not.toBeChecked())
4747

4848
const recommendInput = getByLabelText(/Would you recommend this movie?/i)
49-
await userEvent.click(recommendInput)
49+
userEvent.click(recommendInput)
5050
expect(recommendInput).toBeChecked()
5151

5252
userEvent.tab()
5353
expect(submitButton).toHaveFocus()
5454
expect(submitButton).toBeEnabled()
55-
await userEvent.type(submitButton, '{enter}')
55+
userEvent.type(submitButton, '{enter}')
5656
expect(emitted().submit[0][0]).toMatchObject(fakeReview)
5757

5858
expect(console.warn).not.toHaveBeenCalled()
5959
})
6060

61-
test('selecting option with user events', async () => {
61+
test('selecting option with user events', () => {
6262
const {getByDisplayValue} = render(Select)
6363
const select = getByDisplayValue('Tyrannosaurus')
6464
expect(select.value).toBe('dino1')
6565

66-
await userEvent.selectOptions(select, 'dino2')
66+
userEvent.selectOptions(select, 'dino2')
6767
expect(select.value).toBe('dino2')
6868

69-
await userEvent.selectOptions(select, 'dino3')
69+
userEvent.selectOptions(select, 'dino3')
7070
expect(select.value).not.toBe('dino2')
7171
expect(select.value).toBe('dino3')
7272
})

0 commit comments

Comments
 (0)