Skip to content

queryByText failing when querying a component that returns a string #50

Closed
@hnordt

Description

@hnordt
  • dom-testing-library version: 2.4.0
  • react version: 16.3.2

Relevant code or config:

import "dom-testing-library/extend-expect"

import React from "react"
import { render } from "react-testing-library"

const App = () => "Hello World!"

test("App renders without crashing", async () => {
  const { queryByText } = render(<App />)
  expect(queryByText("Hello World!")).toBeInTheDOM()
})

What you did:

I ran the test.

What happened:

It returned an error:

Cannot read property 'match' of null

TypeError: Cannot read property 'match' of null
    at module.exports.str (https://j4rkx7jmlv.codesandbox.io/node_modules/strip-indent/index.js:3:20)

Reproduction:

https://codesandbox.io/s/j4rkx7jmlv

Problem description:

I expect queryByText() to work with components that return a string.

Suggested solution:

Improve queryByText() so it supports components that return a string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions