Skip to content

Add support for <br /> (line breaks) when matching text #750

Closed
@EvgenyOrekhov

Description

@EvgenyOrekhov

Describe the feature you'd like:

Given the following markup:

<div>Hello<br />World</div>

considering that innerText of the above element would be "Hello\nWorld" (see this JSFiddle), I expect that I would be able to use this query:

screen.getByText("Hello\nWorld");

but it throws the following error:

TestingLibraryElementError: Unable to find an element with the text: Hello
World. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

This example on CodeSandbox

Suggested implementation:

Describe alternatives you've considered:

I've considered using a custom function, like the error message suggests, but this is my first experience with Testing Library, and I don't really know how to do it yet.

And since it's a simple case, I would rather like to use a simple query, without providing any custom functions.

Teachability, Documentation, Adoption, Migration Strategy:

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