-
Notifications
You must be signed in to change notification settings - Fork 727
Add guide for events #172
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
Add guide for events #172
Conversation
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.
Looking good. I have a few edit suggestions.
docs/guide-events.md
Outdated
possible. With this in mind, you should be aware that `fireEvent` is not actually | ||
how the user interacts with your application. | ||
|
||
Depending on the interaction multiple events can be fired in the browser and sometimes |
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.
Could we replace this paragraph and the next with this instead?
Depending on the interaction multiple events can be fired in the browser and sometimes | |
Consider `fireEvent.click` which creates a click event and dispatches that event on the given DOM node. This works properly for most situations when you simply want to test what happens when your element is clicked, but when the _user_ actually clicks your button, these are the events that are typically fired (in order): | |
- fireEvent.mouseOver(element) | |
- fireEvent.mouseMove(element) | |
- fireEvent.mouseDown(element) | |
- element.focus() | |
- fireEvent.mouseUp(element) | |
- fireEvent.click(element) | |
And then, if that element happens to be a child of a `label`, then it will also move focus to the form control that the label is labeling. | |
So even though all you really are trying to test is the click handler, by simply using `fireEvent.click` you're missing out on several other potentially important events the user is firing along the way. Again, most of the time this isn't critical for your tests and the trade-off of simply using `fireEvent.click` is worth it. |
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.
Great stuff. Though we start by mentioning a button and then transition to the child of a label. I replaced button with a generic element since I never encountered buttons as children of labels.
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.
Just two more things, then this is mergable!
Closes testing-library/dom-testing-library#293, testing-library/dom-testing-library#292
View rendered text