Dom-testing-library: getByRole can't find button by name if title is ""

Created on 20 Aug 2020  路  3Comments  路  Source: testing-library/dom-testing-library

  • @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:

bug released

All 3 comments

Firefox also reports that the button has a name.

Thanks for the report. Will take a look at it over at https://github.com/eps1lon/dom-accessibility-api/issues/393

:tada: This issue has been resolved in version 7.22.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings