screen.getByText(match: Matcher)
requires a Matcher
that can be of type string
, RegExp
, or MatcherFunction
. If using the latter, it should be of the form
(content: string, element: HTMLElement) => boolean
.
Expectation:
screen.getByText((content, element) => element.className.includes("my-class") && content.includes("text to search for"));
involves searching through the DOM for an element with the class name my-class
containing the text text to search for
Actual: TestingLibraryElementError: The element with the text was not found: element.className.includes("my-class") && content.includes("text to search for")
It seems like the MatcherFunction prototype is being interpreted as a string. Could this issue be related to the lambda syntax?