testing-library / testing-library/dom-testing-library

errror when using `getAllByText` with a function matcher

Open
#798 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation
Dominant language
JavaScript
Stars
3.3k
Forks
474
PR merge metrics
No merged PRs in 30d

Description

  • @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:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the getAllByText and getByText implementations and reproduce the supplied function-matcher example in the project's tests. Compare the two code paths and add regression coverage for multiple matching elements; done means getAllByText no longer raises the reported queryName error while preserving its expected results.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.