Skip to content

getByRole does not support exact option #1157

Closed
@JesusTheHun

Description

@JesusTheHun

Versions

@testing-library/jest-dom v5.16.5
@testing-library/react v13.3.0

The problem

// Given that an option with the name "Option 1"
getByRole("option", { name: "option 1", exact: false }) // should return the element, but doesn't

Reproduction:

https://codesandbox.io/s/react-testing-library-repro-getbyrole-exact-false-5zzq2v

Problem description:

In the documentation we only see the use of regex when using getByRole and the use of exact when using getByText. However the Typescript definition says the exact option is available for getByRole.
So it is either a type error or a runtime code error.

Suggested solution:

  • Improve the documentation
  • Fix the type
  • Fix the implementation

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