Skip to content
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

Closed
rkoval opened this issue Apr 25, 2018 · 3 comments
Labels
good first issue 🤙 Good for newcomers

Comments

@rkoval
Copy link
Contributor

rkoval commented Apr 25, 2018

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 of

'    white  

  space   '

could be stripped to just

'white space'

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 the textContent as-is in the HTML.

@gregberge
Copy link
Member

I prefer to not change the textContent, you can use a RegExp like white.*space and it should work.

@rkoval
Copy link
Contributor Author

rkoval commented Apr 26, 2018

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'

@gregberge
Copy link
Member

@rkoval OK can you implement it?

gregberge added a commit that referenced this issue May 3, 2018
BREAKING CHANGE: Text is now trimmed and no longer evaluated as a RegExp. If you want this behaviour, use a true RegExp.

Closes #51
Closes #50
gregberge added a commit that referenced this issue May 3, 2018
BREAKING CHANGE: Text is now trimmed and no longer evaluated as a RegExp. If you want this behaviour, use a true RegExp.

Closes #51
Closes #50
AGuyWhoIsBored added a commit to polyflowbuilder/polyflowbuilder that referenced this issue Aug 1, 2023
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue 🤙 Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants