Skip to content

expose more functions from role-helpers #1356

Open
@kkoo95

Description

@kkoo95

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions