Skip to content

ByRole queries don't find node with name when the node with role has the name as a direct string child #1140

Closed

Description

@AugustinLF

Describe the bug

getByRole(role, {name}) doesn't work when the target node doesn't have components as a child.

test('returns an element when the direct child is text', () => {
    const { getByRole } = render(
      <Text accessibilityRole="header" testID="target-header">
        About
      </Text>
    );

    // assert on the testId to be sure that the returned element is the one with the accessibilityRole
    expect(getByRole('header', { name: 'About' }).props.testID).toBe(
      'target-header'
    );
  });

Issue open for better tracking, see #1139 for discussions.

Versions

RNTL 11.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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