-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Have .contains() strip new lines of targets. #92
Comments
Should it also strip newlines/whitespaces between words or just beginning and trailing of the entire string? |
hmm, the title is "Have .contains() strip new lines of targets". but reading the description, shouldn't the title be "Have .contains() replace new lines with space"? and for the record, as the documentation for ps. i dont think automatically replacing anything other than leading/trailing whitespace in a string is a good idea. (removing would be catastrophic: |
I also would like to have it ignoring whitespace. |
@plehnen Interesting, I didn't know this existed. You could include chai-string in Cypress and use this assertion if it's a blocker for anything. See this example on how to extend chai. |
@jennifer-shehane I do include chai-string. But it doesn't work as easy as in the example. import chai from 'chai';
import chaiString from 'chai-string';
chai.use(chaiString);
// this is a hack, because it seems that cypress does not really support 3rd party chai plugins yet
const { expect } = chai;
const hasTextIgnoreSpaces = (selector, text) => {
cy.get(selector).invoke('text')
.should(t => expect(t).to.equalIgnoreSpaces(text));
}; |
A simple workaround for now is to use regex. For example, I have a span with "50 widgets" in HTML template like this: <span id="my-quantity-of-widgets-a8bc90dd">50
widgets</span> I can match it with cy.get('span[id^="my-quantity-of-widgets-a8bc90dd"]').contains(/50(\s)*widgets/); Relevant code chunk in the driver:
|
The code for this is done in cypress-io/cypress#5653, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Description
Sometimes when I issue
.contains()
commands with text I expect to be found, it doesn't match my element as expected due to extra whitespace/new lines in my element.Code
HTML
Test
Web Page
Additional Info
Checking jQuery's
.text()
in console, I see there is whitespace leading/trailing the actual text.Could it be possible to remove whitespace/new lines of el's when trying to match with
.contains
?The text was updated successfully, but these errors were encountered: