dom-testing-library
dom-testing-library copied to clipboard
errror when using `getAllByText` with a function matcher
-
@testing-library/domversion: 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:
Hi @benmonro :),
I have tried by this small example and I'm not having any issue. Could you please provide more info about your test?
renderIntoDocument(`
<div>
<span>foo bar baz</span>
<span>foo bar baz</span>
<span>foo bar baz</span>
</div>
`)
expect(
screen.getAllByText((_content, el) => el.textContent === 'foo bar baz'),
).toHaveLength(3)