Skip to content

Cryptic error message when passing a number to getByText #826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kaiyoma opened this issue Nov 17, 2020 · 2 comments · Fixed by #829
Closed

Cryptic error message when passing a number to getByText #826

kaiyoma opened this issue Nov 17, 2020 · 2 comments · Fixed by #829
Labels
enhancement New feature or request released

Comments

@kaiyoma
Copy link

kaiyoma commented Nov 17, 2020

  • @testing-library/dom version: 7.26.6
  • Testing Framework and version: Jest 26.6.3
  • DOM Environment: jsdom 16.4.0

Relevant code or config

screen.getByText(42)

What you did:

Accidentally passed a number to getByText.

What happened:

    TypeError: matcher.test is not a function
      at fuzzyMatches (../../node_modules/@testing-library/dom/dist/matches.js:30:20)
      at ../../node_modules/@testing-library/dom/dist/queries/text.js:37:142
          at Array.filter (<anonymous>)
      at queryAllByText (../../node_modules/@testing-library/dom/dist/queries/text.js:37:127)
      at ../../node_modules/@testing-library/dom/dist/query-helpers.js:87:17
      at ../../node_modules/@testing-library/dom/dist/query-helpers.js:62:17
      at getByText (../../node_modules/@testing-library/dom/dist/query-helpers.js:106:19)
      at Object.<anonymous> (src/LabelValueTable/__test__/index.spec.tsx:20:23)

Problem description:

This error message is very confusing and not helpful. This seems like a common mistake, so a more helpful error message would save everyone a lot of time.

Suggested solution:

Improve the error message to be clear.

@kentcdodds
Copy link
Member

We could probably just pass it to String and avoid the error altogether.

@github-actions
Copy link

🎉 This issue has been resolved in version 7.27.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants