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

Add toHaveErrorMessage matcher #370

Merged

Conversation

SevenOutman
Copy link
Contributor

@SevenOutman SevenOutman commented May 30, 2021

What:

feature: .toHaveErrorMessage matcher to check whether an invalid element has requested error message.

Why:

This PR is basically a replacement of the stale PR #258 which implements proposal #256.

How:

Most implementation and tests are copied from the original PR with some modification to address testing issues.

Checklist:

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 a lot for this. Very thorough implementation and tests. Thanks.

@codecov
Copy link

codecov bot commented Jun 3, 2021

Codecov Report

Merging #370 (2331748) into main (c816955) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #370   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        24    +1     
  Lines          554       584   +30     
  Branches       199       215   +16     
=========================================
+ Hits           554       584   +30     
Impacted Files Coverage Δ
src/to-have-errormessage.js 100.00% <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 c816955...2331748. Read the comment docs.

@gnapse gnapse merged commit 217fdcc into testing-library:main Jun 3, 2021
@gnapse
Copy link
Member

gnapse commented Jun 3, 2021

@all-contributors please add @SevenOutman for code, test

@allcontributors
Copy link
Contributor

@gnapse

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

@gnapse gnapse mentioned this pull request Jun 3, 2021
4 tasks
@github-actions
Copy link

github-actions bot commented Jun 3, 2021

🎉 This PR is included in version 5.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@SevenOutman SevenOutman deleted the pr/add-to-have-errormessage branch June 4, 2021 02:07
@SevenOutman
Copy link
Contributor Author

@kentcdodds I'd recommend using this matcher for testing form validation instead of toHaveDescription in your showcases. What do you think?

@kentcdodds
Copy link
Member

Sounds great. What showcase are you referring to?

@SevenOutman
Copy link
Contributor Author

What showcase are you referring to?

I remember seeing several in Testing Javascript courses, but couldn't recall which exactly.

@kentcdodds
Copy link
Member

I'll keep it in mind in the future! Thanks 👍

@ITenthusiasm
Copy link
Contributor

ITenthusiasm commented Jul 18, 2023

Seeing this after the fact. 😅

Just as a heads up @kentcdodds @SevenOutman, the aria-errormessage attribute doesn't have Full Screen Reader support yet. I was very sad to find this out. For instance, I can hear error messages on iOS, but not on MacOS -- as the provided link shows. (From what I know so far, this seems to be a Screen Reader problem, not a Browser problem. Chrome, for instance, is perfectly able to determine an element's error message from aria-errormessage in the devtools.)

It seems that for right now, the recommended way of conveying error messages to users is still to use aria-describedby. But! There's much more support for aria-errormessage now than there used to be a year ago. I'm really hopeful/excited for full support to come through, as aria-errormessage could help with a lot of things.

In the meantime, any documentation or examples that use aria-errormessage might want to have some warnings attached with the aforementioned information.

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.

None yet

4 participants