Add support for <br /> (line breaks) when matching text
See original GitHub issueDescribe 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.
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:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Break the line in a concatenated string based on a matching ...
Using "br". You can simply append the text using innerHTML like: var content = "Test 1<br>Test 2<br>Test 3" document.
Read more ><br>: The Line Break element - HTML - MDN Web Docs - Mozilla
The HTML element produces a line break in text (carriage-return). It is useful for writing a poem or an address, where the division...
Read more >Insert a line break in a cell - Microsoft Support
To add space between lines of text in a cell, double-click the cell, click where you want to break the line, and then...
Read more >The Dos and Don'ts of Adding an HTML Line Break
In HTML, the <br> element creates a line break. You can add it wherever you want text to end on the current line...
Read more >Using the \n formula to add line breaks in Airtable
When working with formulas, especially when combining several fields of information, it is often helpful to program in line breaks and other ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

That makes sense. One thing you could do is this:
That would output everything with the
<br />. I’m just not sure how I feel about encoding things like this in the query because you could implement that same thing using spans/divs/etc.@EvgenyOrekhov
Might not be the best solution but it’s working for me.