Skip to content
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

Remove lines about using fireEvent to gain focus or blur #187

Merged
merged 1 commit into from
Jan 20, 2020

Conversation

jzarzeckis
Copy link
Contributor

Close #186

What:

Removing lines in documentation that state you can use fireEvent.focus(element)

Why:

To avoid confusion. More details & example provided in #186

Checklist:

  • Documentation
  • Tests N/A
  • Updated Type Definitions N/A
  • Ready to be merged

@codecov
Copy link

codecov bot commented Jan 17, 2020

Codecov Report

Merging #187 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #187   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          19     19           
  Lines         234    234           
  Branches       57     57           
=====================================
  Hits          234    234

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 760409a...cc74c04. Read the comment docs.

Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing the documentation! I would rather apply the suggestions from #186 (comment) though i.e. input.blur() instead of fireEvent.blur(input)

@weyert
Copy link

weyert commented Jan 17, 2020

Yes, or people would just use user-event instead ;)

@gnapse
Copy link
Member

gnapse commented Jan 17, 2020

Thanks for this contribution, and for noticing this in the first place.

Indeed, using user-event can fix this. But for the context of our documentation, I'd say I second @eps1lon's suggestion: instead of removing the entire example, we can change it so it calls element.focus() instead of fireEvent.focus().

@jzarzeckis
Copy link
Contributor Author

@eps1lon if you look at the diff, you will see that the example with element.focus() hasn't been removed:

This allows you to assert whether an element has focus or not.
#### Examples
```html
<div><input type="text" data-testid="element-to-focus" /></div>
```
##### Using document.querySelector
```javascript
const input = document.querySelector(['data-testid="element-to-focus"'])
input.focus()
expect(input).toHaveFocus()
input.blur()
expect(input).not.toHaveFocus()
```

- ##### Using DOM Testing Library
-
- ```javascript
- const input = queryByTestId(container, 'element-to-focus')
-
- fireEvent.focus(input)
- expect(input).toHaveFocus()
-
- fireEvent.blur(input)
- expect(input).not.toHaveFocus()
- ```

Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eps1lon if you look at the diff,

I did. The diff does not tell me that we already had a working example above.

This change is good as-is. The extra documentation wasn't needed in the first place.

@gnapse
Copy link
Member

gnapse commented Jan 20, 2020

@jzarzeckis indeed. But the existence of two examples was not because one used element.focus() and the other fireEvent.focus(). Both examples exist so that one shows an example that uses @testing-library/dom and the other shows how an example looks like when using native DOM APIs.

So your fix should be about making the example that was incorrectly using fireEvent to now use element.focus().

If you wonder why we show duplicate examples like this, indeed, I share the pain, and I've been meaning to remove that duplication. I'll accept your PR as is, because I'll remove that duplication in our documentation soon.

@gnapse gnapse merged commit c919520 into testing-library:master Jan 20, 2020
@gnapse
Copy link
Member

gnapse commented Jan 20, 2020

Follow up: created #188 to solve that documentation duplication for good. In case anyone wants to take a look or chime in.

@gnapse
Copy link
Member

gnapse commented Jan 22, 2020

🎉 This PR is included in version 5.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gnapse
Copy link
Member

gnapse commented Jan 24, 2020

@all-contributors please add @jzarzeckis for doc

@allcontributors
Copy link
Contributor

@gnapse

I've put up a pull request to add @jzarzeckis! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Misleading documentation for toHaveFocus
4 participants