-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expect-puppeteer: trim out redundant whitespace in textContent
when doing text
matching
#51
Comments
I prefer to not change the |
Unfortunately, not when targeting any nested trees that result in newlines between strings to match (which, in a lot of projects i imagine, is most of the meaningful text). You have to expand the regex to appease every newline and surrounding whitespace on every line until you get to the strings you want to match. Would you at least be open to adding a secondary API for this sort of behavior that will only attempt to strip when you pass the right argument? I would be happy to implement, as it's very easy to do. Example: const textContent = ` white
space `
const strippedTextContent = textContent.replace(/\s+/g,' ').trim() // results in 'white space' |
@rkoval OK can you implement it? |
* apparently this is where our test flakiness comes from -- sometimes based on how PlayWright interprets HTML/how it's laid out, there are extra spaces detected see argos-ci/jest-puppeteer#51 apparently this isn't a PlayWright-specific issue
When matching on
textContent
, a lot of the time, there will be extra whitespace/newlines surrounding the text you're matching based on how the HTML looks within the element you're matching. It could be nice to strip all of the redundant whitespace out when doing the comparison within this library as well such that consumers of it don't need to account for that whitespace in their comparison strings.For example, a
textContent
ofcould be stripped to just
to allow matching by passing just
'white space'
without needing wildcards in the comparison string. This could vastly improve test cases asserting that text exists. This could also perhaps be configurable too in case someone actually needed thetextContent
as-is in the HTML.The text was updated successfully, but these errors were encountered: