-
Notifications
You must be signed in to change notification settings - Fork 401
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
toHaveErrorMessage #256
Comments
Sure, this is really nice. Also, "Today I Learned" that this attribute and aria feature even existed. Thanks! In reading the spec for this attribute, yes, you are right that this matcher should assert that Another thing that caught my eye from the spec is that the referenced element that holds the error message should be visible (screen reader visible at least). So I think the matcher should also validate that the referenced element does not have But I think it does not hurt we still include the check. At the very least, we'd help authors catch the case where they hide/show the element by applying In any case, I'm happy to take this myself, but I won't have time until about the next weekend or the other one. If you or anyone else is up to it, feel free to take a crack at it. Thanks! |
I'm down to write up an initial PR for review to cover at least the error message and invalid assertion. If we include within scope that the error message be visible, is that as simple as calling |
I'm ok with leaving that part of the spec out of the initial version. But leaving it to a separate assertion would require the user writing the tests to grab that element's reference first, which would make it cumbersome and not something with which this assertion would be helping with. They' need to get into the implementation details that this new custom matcher would be trying to give them. But yes, feel free to ignore that part. We can always improve it later. |
🎉 This issue has been resolved in version 5.17.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Describe the feature you'd like:
I'd like an assertion for the
aria-errormessage
attribute. It accepts a list of id strings formatted identically to the formataria-describedby
accepts.https://www.w3.org/TR/wai-aria-1.1/#aria-errormessage
Browser support was poor a year ago but I can't seem to find any up-to-date information on its support level. There is some chance that this is unsupported enough to be not worth implementing, but on a long enough timeline I think it'll fit well here.
Usage
Suggested implementation:
The implementation would be nearly a clone of
toHaveDescription
except the elements it reads come from thearia-errormessage
attribute instead ofaria-describedby
It could also assert that
aria-invalid
is trueI'm willing to make a PR for inclusion but I'm new to open source so I wanted to get feedback up front
Describe alternatives you've considered:
Teachability, Documentation, Adoption, Migration Strategy:
toHaveErrorMessage
This allows you to check whether the given element has an error message or not.
An element gets its error message via the
aria-errormessage
attribute.Set this to the
id
of one or more other elements. These elements may be nestedinside, be outside, or a sibling of the passed in element.
Whitespace is normalized. Using multiple ids will
join the referenced elements’ text content separated by a space.
When a
string
argument is passed through, it will perform a wholecase-sensitive match to the error message text.
To perform a case-insensitive match, you can use a
RegExp
with the/i
modifier.
To perform a partial match, you can pass a
RegExp
or useexpect.stringContaining("partial string")
.Examples
The text was updated successfully, but these errors were encountered: