Skip to content

expose more functions from role-helpers #1356

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

Open
kkoo95 opened this issue Apr 29, 2025 · 3 comments
Open

expose more functions from role-helpers #1356

kkoo95 opened this issue Apr 29, 2025 · 3 comments

Comments

@kkoo95
Copy link

kkoo95 commented Apr 29, 2025

Describe the feature you'd like:

Expose all the computeAriaXXX functions from role-helpers to provide greater flexibility for test authoring. This would enable writing tests like this:

const optionsList = within(getByRole(document.body, 'listbox', { name: /Options list/ }));

expect(
    optionsList.queryAllByRole('option').map(e => ({
        name: computeAccessibleName(e),
        selected: computeAriaSelected(e),
    }))
).toEqual([
    {  name: 'manager1', selected: true },
    {  name: 'external2', selected: false },
]);

Here, we combine the verification of the order and the specific ARIA properties for each option into a single expectation. Otherwise, it would require at least two steps to achieve the same result.

expect(optionsList.queryAllByRole('option').map(e => computeAccessibleName(e))).toEqual(['manager1', 'external2']);
expect(optionsList.queryByRole('option', { name: 'manager1', selected: true })).toBeDefined();
expect(optionsList.queryByRole('option', { name: 'external2', selected: false })).toBeDefined();
@MatanBobi
Copy link
Member

Thanks for opening this one @kkoo95. The computeAccessibleName function is imported from dom-accessibility-api, if you want that one, you can npm install and use it.
https://github.com/eps1lon/dom-accessibility-api/tree/main

@kkoo95
Copy link
Author

kkoo95 commented May 6, 2025

hum it's not what i was asking for 😅 @MatanBobi

I noticed indeed that name and description were already available. But I was talking about the other helpers such as computeAriaSelected (see src/role-helpers.js)

@MatanBobi MatanBobi reopened this May 6, 2025
@MatanBobi
Copy link
Member

Missed that, sorry.
IMO this should also probably be exported from DOM-accessibility-api and shouldn't live in our repo.
I currently don't have the capacity to move that functionality there but I do think that we should do it.

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

No branches or pull requests

2 participants