expose more functions from role-helpers
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();
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
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)
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.