Skip to content

getByRole can't find button by name if title is "" #747

@EvgenyOrekhov

Description

@EvgenyOrekhov
  • @testing-library/dom version: 7.22.2
  • Testing Framework and version: Jest (whatever version comes with CodeSandbox)
  • DOM Environment: whatever version comes with CodeSandbox

Relevant code or config:

import React from "react";

export default function App() {
  return <button title="">OK</button>;
}

What you did:

screen.getByRole("button", { name: /ok/i });

What happened:

Unable to find an accessible element with the role "button" and name `/ok/i`

Here are the accessible roles:

  button:

  Name "":
  <button
    title=""
  />

Reproduction:

https://codesandbox.io/s/happy-chandrasekhar-311qt?file=/src/App.js

Problem description:

Chrome reports that the button has a name:

image

But getByRole says it does not.

JSFiddle: https://jsfiddle.net/91retmv2/

Suggested solution:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions