-
Notifications
You must be signed in to change notification settings - Fork 468
Description
dom-testing-library
version:5.5.1
node
version:10.16.0
npm
(oryarn
) version:6.9.0
What you did:
Tried to get an anchor element (<a href="http://whatever.com">
).
Since it wasn't working (even though the implicit ARIA role exists in anchor elements as long as they have a href
attribute) I turned to DTL and added <a href="http://link.com" data-testid="a-link">link</a>
to role-helpers test.
What happened:
Test continued to pass.
What did you expect:
Test to fail, since logRoles
would've logged a link
implicit ARIA role with the anchor element within
Reproduction:
- Add
<a href="http://link.com" data-testid="a-link">link</a>
to role-helpers test. - Run tests.
Suggested solution:
I've been able to track it down to makeElementSelector()
, where we extract value
and use it to create the node selector expression:
.map(({name: attributeName, value}) => `[${attributeName}=${value}]`)
(source)
the resulting output for an anchor element is a[href=undefined]
. Thus, if I change my link to <a href="undefined">
, the elements is found and test starts to fail - as expected :)
However, not sure what the fix is. Why is the "=value" part needed? Should we just check for value
to be truthy, and otherwise skip it? It'd generate a a[href]
selector, which would come in handy to find links. Another option is to get the "http://whatever.com" part somehow, and add it to the element selector query.
What are your thoughts? I'm happy to tackle this if we reach an agreement 👍 I'm gonna open a draft PR with the updated test cases, so we can work from there.
Thanks!