should('have.text', ...) should ignore leading and trailing whitespace
See original GitHub issueIf your HTML happens to have whitespace in the tag, e.g., <div> foo </div>
, that text will not impact how the user sees the page, unless it is a <pre>
element. I don’t think that the 'have.text'
assertion should fail just because it found ' foo '
when it was expecting 'foo'
.
If you’re not willing to change this (since it is technically a breaking change), maybe there should be a have.text.trimmed
?
Current behavior:
should('have.text', ...)
fails if the HTML contains whitespace, even if that whitespace doesn’t impact the rendered content.
Desired behavior:
should('have.text', ...)
should ignore leading and trailing whitespace for elements that won’t render it. Elements like pre
(and elements with certain white-space
css values) should still consider leading and trailing whitespace.
Versions
3.2.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:57
- Comments:20 (6 by maintainers)
Top GitHub Comments
One way to go about it is:
I also encountered the same issue so I use: