testing-library / testing-library/dom-testing-library

Accessible name not based on placeholder

Open
#926 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
3.3k
Forks
474
PR merge metrics
No merged PRs in 30d

Description

  • @testing-library/dom version: 7.28.1
  • Testing Framework and version: Jest 26.6.0
  • DOM Environment: jsdom 16.4.0 (also tested with cypress 6.1.0)
  • Other: create-react-app with react-scripts 4.0.3
Relevant code or config:

App.js

function App() {
  return (
    <div className="App">
      <input type="text" placeholder="placeholder-value" />
    </div>
  );
}
export default App;

App.test.js

test('finds textbox by role and placeholder', () => {
  render(<App />);
  expect(screen.getByRole('textbox', { name: 'placeholder-value' })).toBeVisible()
});
What you did:

Run test (via yarn test)

What happened:

The test fails with the message:

TestingLibraryElementError: Unable to find an accessible element with the role "textbox" and name "placeholder-value"

    Here are the accessible roles:

      textbox:

      Name ""

Note that the value for Name is empty

Reproduction:

Relevant commit: https://github.com/nphmuller/dom-testing-placeholder-repro/commit/1786a0a4c048f244a469ac8a0fa1bdaf92fc54a3

Problem description:

When looking at the Chrome dev tools, the accessible name is also calculated based on the placeholder. See the screenshot below. dom-testing-library seems to ignore the placeholder value for calculating this name.

image

Suggested solution:

It would really help if you could support the placeholder during accessible name calculation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the App.js and App.test.js reproduction and run yarn test to confirm the current accessible-name result. Trace the accessible-name calculation entry point used by getByRole, then verify the behavior against the reported placeholder example. Done means the textbox can be found with name "placeholder-value" and the reproduction test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
accessibility, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.