You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a project that does not use TypeScript (alas!), I passed undefined instead of a valid matcher to getByRole.
What happened:
TypeError: Cannot read property 'test' of undefined
9 | const view = render(<div />);
10 |
> 11 | view.getByRole(undefined);
| ^
13 |
at matches (../../node_modules/@testing-library/dom/dist/matches.js:39:20)
at ../../node_modules/@testing-library/dom/dist/queries/role.js:78:47
at Array.some (<anonymous>)
at ../../node_modules/@testing-library/dom/dist/queries/role.js:78:26
at Array.filter (<anonymous>)
at queryAllByRole (../../node_modules/@testing-library/dom/dist/queries/role.js:57:54)
at ../../node_modules/@testing-library/dom/dist/query-helpers.js:89:17
at ../../node_modules/@testing-library/dom/dist/query-helpers.js:64:17
at getByRole (../../node_modules/@testing-library/dom/dist/query-helpers.js:108:19)
For all matchers that eventually call to matches, including getByText and getByRole, passing an invalid matcher such as null or undefined crashes with a confusing error message. Users likely did not mean to pass an invalid matcher to the search.
Similar to #609, I'd like to send a PR that adds an explicit error message for this case.
The text was updated successfully, but these errors were encountered:
JoshuaKGoldberg
changed the title
"Cannot read property 'test' of undefined." when undefined passed to fuzzyMatches
"Cannot read property 'test' of undefined." when undefined passed to matches
Jul 25, 2020
@testing-library/dom
version: 7.19.0jest
@26.1.0 and@testing-library/react
@10.4.7jsdom
@11.12.0Relevant code or config:
What you did:
In a project that does not use TypeScript (alas!), I passed
undefined
instead of a valid matcher togetByRole
.What happened:
Reproduction:
https://codesandbox.io/s/react-testing-library-getbytext-undefined-r6ygs for a version showing
null
andgetByText
causing the same issue.Problem description:
For all matchers that eventually call to
matches
, includinggetByText
andgetByRole
, passing an invalid matcher such asnull
orundefined
crashes with a confusing error message. Users likely did not mean to pass an invalid matcher to the search.dom-testing-library/src/matches.js
Line 27 in 639294c
Suggested solution:
Similar to #609, I'd like to send a PR that adds an explicit error message for this case.
The text was updated successfully, but these errors were encountered: