Skip to content

Cryptic error message when passing a number to getByText #826

Closed
@kaiyoma

Description

@kaiyoma
  • @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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions