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

Improved error messaging for toHaveFocus assertion #304

Merged

Conversation

syneva-runyan
Copy link
Contributor

What:

Added more details to the .toHaveFocus assertion error message

Why:
The DOM output when an element is not properly focus does not show any meaningful hints to why an assertion may have failed, which can make errors more difficult to debug

Screen Shot 2020-11-02 at 10 54 14 AM

How:
Added additional verbiage to the error message
Screen Shot 2020-11-02 at 10 53 47 AM

Checklist:

  • Documentation
  • Tests
  • x] Updated Type Definitions
  • Ready to be merged

Open to feedback on the messaging content or verbiage!

Copy link
Member

@gnapse gnapse left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. I can see how the current output is not super helpful.

However, what you propose is not accurate. Probably the same confusing nature of this message lead you to misinterpret it. But the fact is that what we print in the part of the error labeled with "Received" is the element that had the focus. It is meant to let you know where the focus lied instead of where the test expected.

In the case of your screenshot the focus lies in the body element, which is what happens usually when the element that had the focus was removed or hidden from being rendered.

src/to-have-focus.js Outdated Show resolved Hide resolved
@syneva-runyan
Copy link
Contributor Author

@gnapse thanks for the feedback! Updated the verbiage to read:

Expected element with focus:"...
Received element with focus:"...

@gnapse
Copy link
Member

gnapse commented Nov 13, 2020

@syneva-runyan sorry, the other day I noticed that the build is failing, and forgot to notify you. I took a look at the build on travis and it's not clear why it failed. A CI process stopped after 10 minutes without output or something like that. I also don't find a way to request travis to restart the build. I wonder if you can push a change (maybe an extra empty commit) to see if a new build is launched.

@syneva-runyan
Copy link
Contributor Author

@gnapse no worries, just pushed some commits and looks like it's running now

@codecov
Copy link

codecov bot commented Nov 13, 2020

Codecov Report

Merging #304 (166ecf0) into master (c11f9c5) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #304   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines          315       315           
  Branches        72        72           
=========================================
  Hits           315       315           
Impacted Files Coverage Δ
src/to-have-focus.js 100.00% <ø> (ø)

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 c11f9c5...166ecf0. Read the comment docs.

@gnapse gnapse merged commit c79faa2 into testing-library:master Nov 13, 2020
@gnapse
Copy link
Member

gnapse commented Nov 13, 2020

@all-contributors add @syneva-runyan for code

@allcontributors
Copy link
Contributor

@gnapse

I've put up a pull request to add @syneva-runyan! 🎉

@gnapse
Copy link
Member

gnapse commented Nov 13, 2020

🎉 This PR is included in version 5.11.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

2 participants