Skip to content

Get/Log Roles helpers doesn't return anchors when querying link roles #313

@afontcu

Description

@afontcu
  • dom-testing-library version: 5.5.1
  • node version: 10.16.0
  • npm (or yarn) 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:

  1. Add <a href="http://link.com" data-testid="a-link">link</a> to role-helpers test.
  2. 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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions