Text values encoded with can't be asserted
See original GitHub issueReproduced on version 6.0.1
Have a page with markup like:
<div class="myClass">hello world</div>
run cypress with test like:
cy.get('.myClass').should('have.text', 'hello world')
cy.get('.myClass').should('have.text', 'hello world')
cy.get('.myClass').should('contain.text', 'hello world')
cy.get('.myClass').should('contain.text', 'hello world')
cy.get('.myClass').contains('hello world').should('exist')
cy.get('.myClass').contains('hello world').should('exist')
All mentioned tests fails, and there does not seem to be any way to verify the content without doing extra text manipulation first.
On top of that, both the AssertionError in the left side-bar and in the console log shows the same counterproductive message of:
expected ‘<div.myClass>’ to have text ‘hello World’, but the text was ‘hello World’
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Asserting text of element with   - mocha.js - Stack Overflow
I assume you are trying to to test that .c-ledger__row-amount is "DKK 15.00". Try this. cy.get(".c-ledger__row- ...
Read more >Non-breaking space | Cypress examples (v6.5.0)
When using cy.contains command Cypress automatically converts the entity into space character. Thus cy.contains finds element that include .
Read more >getting error: Neither the SAML assertion nor response is signed in ...
I am able to authenticate to the IDP but the response has some issues when AssertionConsumerService is called, specifically when samlServiceProvider.
Read more >MUnit assert HTTP status code and response headers in Mule 4
Hey Guys. I'm trying to figure out how to assert HTTP status code on my MUnit test case. The assertion that I would...
Read more >dxml.util - jmdavisprog.com
"Normalizes" the given text and transforms character references into the ... can't be directly represented in the text fields or attribute values in...
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 FreeTop 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
Top GitHub Comments
I wrote a few ways that you could assert on this below.
The assertion in your tests has all lowercase ‘hello world’ and the Div has ‘hello World’ with a capital W. If you want it to not match the exact casing, then you need to pass:
{ matchCase: false }
to.contains()
, but any other assertion would fail without the exact casing.@kiwdahc I have added example for your case here https://github.com/cypress-io/cypress-fiddle/commit/9dec37dbbefa0572dcdb3c3b63bb1cfaab43eecd
Short story:
.filter(':contains...
uses jQuery contains selector, thus you need to use the unicode character for non-breaking space entity which is\u00a0
.I will add notes to your docs