Skip to content

Finding an SVG using aria-labelledby has no results #271

@paularmstrong

Description

@paularmstrong
  • dom-testing-library version: latest
  • react version: latest
  • node version: n/a
  • npm (or yarn) version: n/a

Relevant code or config:

const MyComponent = () => (
  <div>
    <svg aria-labelledby="tacos" />
    <div id="tacos">this is tacos</div>
  </div>
);

What you did:

  const { getByLabelText } = render(<MyComponent />);
  expect(getByLabelText("tacos")).not.toBeUndefined();

What happened:

No result for element labelled by "tacos"

Reproduction:

See codesandbox: https://codesandbox.io/s/reacttestinglibrary-demo-ollox?fontsize=14

Test output:

Unable to find a label with the text of: tacos

<body>
  <div>
    <div>
      <svg
        aria-labelledby="tacos"
      />
      <div
        id="tacos"
      >
        tacos
      </div>
    </div>
  </div>
</body>

Error: Unable to find a label with the text of: tacos

<body>
  <div>
    <div>
      <svg
        aria-labelledby="tacos"
      />
      <div
        id="tacos"
      >
        tacos
      </div>
    </div>
  </div>
</body>

Problem description:

There's no way to find an SVG element that is using aria-labelledby, though the labelText documentation indicates that this should work.

Suggested solution:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions