question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: getByRole('paragraph') doesn't work

See original GitHub issue
test(
  'getByRole("paragraph")',
  withBrowser.headed(async ({ utils, screen }) => {
    await utils.injectHTML(`<p>This is a paragraph</p>`);
    // throws
    const paragraph = await screen.getByRole('paragraph');
  })
);

The paragraph role is added automatically to the element by the browser. It shows up in the accessibility tree in Chrome DevTools. But the above fails.

Screen Shot 2021-12-01 at 5 35 39 PM

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
calebebycommented, Dec 2, 2021

I think this role was added in the latest aria spec which isn’t widely supported by tooling/browsers yet. I could be misremembering though, I will look into it

0reactions
calebebycommented, Dec 6, 2021

Oh now I am noticing that aria 1.1 is not the latest version, aria 1.2 is the latest published version. 1.2 lists the paragraph role: https://www.w3.org/TR/wai-aria-1.2/#paragraph. It shows <p> as a “related concept” which I don’t know if that means it is applied automatically. The HTML-aria spec still says <p> has no implicit role: https://www.w3.org/TR/html-aria/#el-p

Read more comments on GitHub >

github_iconTop Results From Across the Web

getByRole query for paragraph not working during React testing
getByRole uses the HTML role of different elements. Paragraph is not a valid role, that's why your query doesn't work.
Read more >
getByRole query for paragraph not working during React ...
getByRole uses the HTML role of different elements. Paragraph is not a valid role, that's why your query doesn't work. You can read...
Read more >
ByRole | Testing Library
getByRole ('button') would only return the Close dialog -button. To make assertions about the Open dialog -button you would need to use ...
Read more >
getByRole should support fallback roles · Issue #411 - GitHub
This is what I was trying to say: An element doesn't have multiple roles in a given environment. It has a single one....
Read more >
Making sure you're using the correct query - Tim Deschryver
The short answer to "which query should I use", is most of the time the *ByRole query. There are some cases that this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found