-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add @testing-library/user-event to the project
#39360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Size Change: +151 B (0%) Total Size: 1.16 MB
ℹ️ View Unchanged
|
784d862 to
9f5d486
Compare
| "@testing-library/jest-dom": "5.16.1", | ||
| "@testing-library/react": "11.2.2", | ||
| "@testing-library/react-native": "9.0.0", | ||
| "@testing-library/user-event": "^14.0.0-beta.13", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This the latest available version, and is the recommended one over the previously stable version (13.5.0)
From the official docs:
These docs describe
[email protected]. This is still a pre-release and might be subject to breaking changes if they should be deemed necessary in the light of feedback we receive for this version. All planned breaking changes are already implemented though.
If you are starting or actively working on a project, we recommend to use this pre-release, as it includes important bug fixes and new features.
|
Do you plan to include some best practices for testing components with React Testing Library? that links to: Maybe it's a good opportunity to add a section for testing interaction in the component? |
Good idea, I'll look into it and likely push and update to this PR. |
7eb166e to
bb75f74
Compare
|
Hey @gziolo , I've added some docs as you suggested, let me know if you have any feedback! |
Co-authored-by: Lena Morita <[email protected]>
eddb9de to
8afd1d0
Compare
stokesman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good on the whole. I found a few small things to note.
Co-authored-by: Mitchell Austin <[email protected]>
Thank you @stokesman ! I applied all of your suggestions as they made sense to me. |
mirka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
|
This is great, thank you for making the extra effort to land it in a separate PR with all the documentation additions included. Impressive work 💯 |
|
+1, thanks @ciampo, the added documentation in |
What?
As per #39148 (comment), Add
@testing-library/user-eventto the project and use it inUnitControl's unit tests to showcase how it would be used in the codebase.Why?
The
user-eventlibrary is a companion to@testing-librarythat simulates user interactions by dispatching the events that would happen if the interaction took place in a browser.Compared to the built-in
fireEventutility, theuser-eventlibrary allows a developer to write tests like they would happen if a user interacted with the document. This switch in paradigm moves away from testing implementation details (e.g. firing the exact HTML event), and makes tests written withuser-eventmore meaningful.How?
package.jsonandpackage-lock.jsonUnitControl's unit tests to showcase how to use the newly introduced APIsUnitControlandInputControl'skeydownlisteners to stop using the old and deprecatedevent.keyCode(which is not supported anymore by@testing-library/user-event), use the standardevent.keyproperty insteadTesting Instructions
UnitControl's unit tests are still passing