kentcdodds / testing-react-apps

A workshop for testing react applications
https://www.epicreact.dev/modules/testing-react-apps-v1/testing-react-apps-welcome
Other
1.07k stars 719 forks source link

Exercise 03 - Trigger click event using userEvent doesn't work #91

Closed Boamorte8 closed 1 year ago

Boamorte8 commented 1 year ago

After I check the video of the solution for the extra credit for exercise 03, I found that the unit tests fail. After a little research on StackOverflow I found this answer and I checked the code and image

After I compare it with fireEvent, I can say that the problem is that userEvent.click returns a promise. The click event is not executed. You need to wait until the promise is executed before assert

After you add await the test works well and passes it

kentcdodds commented 1 year ago

Thanks for bringing this up. I guess I neglected to add a note about this in the extra credit description. I've fixed that. Thanks!