Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't find element by role code #1100

Closed
chiptus opened this issue Jan 30, 2022 · 8 comments · Fixed by #1241
Closed

can't find element by role code #1100

chiptus opened this issue Jan 30, 2022 · 8 comments · Fixed by #1241

Comments

@chiptus
Copy link

chiptus commented Jan 30, 2022

  • @testing-library/dom version: 12.1.2
  • Testing Framework and version:
    jest 27.4.3
  • DOM Environment:
    jsdom 16.6.0

Relevant code or config:

component

export default ({ name }) => <code>{name}</code>;

test

import "@testing-library/jest-dom/extend-expect";
import React from "react";
import { render } from "@testing-library/react";
import Code from "../hello";

test("To render a code element", () => {
  const { getByRole } = render(<Code name="Jill" />);
  expect(getByRole("code")).toBeInTheDocument();
});

What you did:

I searched the code element by role code, I expected to find it by https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/structural_roles

What happened:

The element is not found

Reproduction:

https://codesandbox.io/s/fail-to-find-role-code-qpzrs?file=/src/__tests__/hello.js

Problem description:

Per testing-library docs, it seems like it should work, as when I check the role of the element in chrome dev tools, I see 'code' as expected.

Suggested solution:

not sure, I've seen that aria-query doesn't support this role.

@MatanBobi
Copy link
Member

Hi @chiptus!
Thanks for taking the time to open this one :)
Since the issue you're experiencing here is related to implicit roles, aria-query is indeed the package we're using for that.
Though, it's important to note that the Chrome DevTools isn't our source of truth.
We follow the ARIA standards and the way they define implicit roles.
As you can see here, the standard doesn't dictate an implicit role for code element and that's also the reason why aria-query aren't supporting that either.
image

For this specific use-case, I suggest either setting an explicit role on your own or query the element with a different approach :)

I'm closing this one as this is the wanted behavior in this scenario.
Thanks again!

@EmeraldWeb
Copy link

@MatanBobi
Hello, I'm sorry but I think it's better to reopen this issue, because there is corresponding role "code", now:

Снимок экрана 2022-12-26 в 16 07 54

I have run into this problem today, so it will be cool if you're add this role. Thank you.

@MatanBobi
Copy link
Member

Thanks @EmeraldWeb!
I see that the spec was updated.
I've opened an issue for aria-query regarding this :)

@CalebJamesStevens
Copy link

Bumping because this issue still isn't resolved

@MatanBobi
Copy link
Member

@CalebJamesStevens, there's no need to bump this issue, we're waiting for aria-query to release a new version, once they will release it, we will upgrade our dependency.
@eps1lon do you know if there's a roadmap for aria-query release?

@jlp-craigmorten
Copy link
Contributor

v10.0.0 is now live with this update.

@MatanBobi
Copy link
Member

Thanks @jlp-craigmorten!

@all-contributors please add @jlp-craigmorten for question

Copy link
Contributor

@MatanBobi

I've put up a pull request to add @jlp-craigmorten! 🎉

meganesu added a commit to meganesu/personal-site-v2 that referenced this issue Jun 19, 2024
- Needed to be able to access <code/> elements by role (see: testing-library/dom-testing-library#1100)
meganesu added a commit to meganesu/personal-site-v2 that referenced this issue Jun 19, 2024
- Needed to be able to access <code/> elements by role (see: testing-library/dom-testing-library#1100)
meganesu added a commit to meganesu/personal-site-v2 that referenced this issue Jul 4, 2024
* feat(#62): adjust code block styles to accomodate line highlighting

* chore(#62): bump versions @testing-library/* versions

- Needed to be able to access <code/> elements by role (see: testing-library/dom-testing-library#1100)

* chore(#62): major version update for prism-react-renderer

* refactor(#62): improve code readability

* feat(#62): add support for highlight-line comments

* fix(#62): lint

* feat(#62): add support for highlight-start / highlight-end comments

* feat(#62): add support for highlight-next-line comments

* refactor(#62): group initial shouldHighlightLine values

* fix(#62): move codeClassNames into getLineProps, to avoid overwriting the token-line class from prism-react-renderer

* fix(#62): update line highlight color to match Night Owl theme

* refactor(#62): clean up semantic HTML structure
- use figure/figcaption instead of div
- use only one code element (vs one per line)

* fix(#62): fix padding on pre element when no language tag or file tag

* feat(#62): update semantics for highlighted lines to use <mark>

* content(#62): refactor code blocks to use line highlights instead of comments

* fix(#62): make font size consistent on iOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants