-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support complex aria-labelledby queries #1260
Comments
Hi @jossmac, thanks for opening this. |
I wasn't aware of custom queries, thanks for the heads up! Looking at this with fresh eyes, I think there's a sensible way to write the expectation with existing APIs e.g. it('supports "pending" prop', () => {
let { getByRole } = render(<Button pending>Submit</Button>);
expect(
getByRole("button", { name: `Submit ${PENDING_LABEL}` })
).toHaveAttribute("aria-disabled", "true");
}); |
No, I think my mental model was at odds with the library's design decisions. However, I think it should be documented somewhere* that Single ID, works as expected: const { getByLabelText } = render(
<>
<div id="label-1">first</div>
<button aria-labelledby="label-1" />
</>
);
expect(getByLabelText("first")).toBeVisible(); // passes Multiple IDs, does not work as expected: const { getByLabelText } = render(
<>
<div id="label-1">first</div>
<div id="label-2">second</div>
<button aria-labelledby="label-1 label-2" />
</>
);
expect(getByLabelText("first second")).toBeVisible(); // fails. shouldn't really, but understandable knowing what i do now Which could lead to tests passing that really shouldn't e.g. const { getByLabelText } = render(
<>
<div id="label-1">first</div>
<div id="label-2">second</div>
<button aria-labelledby="label-1 label-2" />
</>
);
expect(getByLabelText("first")).toBeVisible(); // passes, incorrectly *Found this documentation under a somewhat confusing heading:
|
Describe the feature you'd like:
I'd like
getByLabelText
to resolve the associated elements ofaria-labelledby
. As I'm writing this it occurs to me that this might be too costly and perhaps better suited to something like axe.Describe alternatives you've considered:
I've resorted to a combination of
getByRole + getByText
and checking IDs.Teachability, Documentation, Adoption, Migration Strategy:
The summarised/pseudo code looks something like:
The desired test would look something like:
The text was updated successfully, but these errors were encountered: