Skip to content

errror when using getAllByText with a function matcher #798

Open
@benmonro

Description

@benmonro
  • @testing-library/dom version: 7.24.1
  • Testing Framework and version:
    "@testing-library/dom": "^7.24.1",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.0.2",
    "@testing-library/user-event": "^12.1.3",
  • DOM Environment: jest

Relevant code or config:

expect(
      screen.getAllByText(
        (_content, el) =>
          el.textContent === "foo bar baz"
      )[0]
    ).toBeInTheDocument();

What you did:

ran the tests

What happened:

got an error:

TypeError: Cannot read property 'queryName' of undefined

Reproduction:

Problem description:

getAllByText has this error, but getByText does not. however getByText will fail when there are more than 1 element returned by the matcher.

Suggested solution:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions