question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'.should' assertion is not working properly with &nbsp

See original GitHub issue

I am trying to assert that a span has the value “0,00 €” but it seems like it doesn’t work properly cy.get(".shipping_amount").should("have.text","0,00 €");

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bahmutovcommented, Dec 7, 2020

We could probably document this edge case in our docs to make finding it easier

Sent from my iPhone

On Dec 7, 2020, at 03:20, Jennifer Shehane notifications@github.com wrote:

Wrote in the other issue, but here’s how you could write this:

it(‘text’, () => { cy.get(‘.shipping_amount’).contains(‘0,00 €’)

cy.get(‘.shipping_amount’).invoke(‘text’).then((text) => { // remove the space char expect(text.replace(/\u00a0/g, ’ ')).equal(‘0,00 €’) })

cy.get(‘.shipping_amount’).invoke(‘text’) // remove the space char .invoke(‘replace’, /\u00a0/g, ’ ') .should(‘eq’, ‘0,00 €’) }) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

0reactions
jennifer-shehanecommented, Dec 7, 2020

Wrote in the other issue, but here’s how you could write this:

it('text', () => {
  cy.get('.shipping_amount').contains('0,00 €')

  cy.get('.shipping_amount').invoke('text').then((text) => {
    // remove the space char
    expect(text.replace(/\u00a0/g, ' ')).equal('0,00 €')
  })

  cy.get('.shipping_amount').invoke('text')
  // remove the space char
  .invoke('replace', /\u00a0/g, ' ')
  .should('eq', '0,00 €')
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Asserting text of element with &nbsp - mocha.js - Stack Overflow
I need to check the text of a Div tag and ensure if it is showing the correct text of not.
Read more >
Confirming the text with non breaking space entity - YouTube
In this video I answer the question from https://github.com/cypress-io/cypress/ issues /15863 by showing how to assert text that uses ...
Read more >
MUnit Spy has failed assertions that do not fail test
The Spy on set-payload works fine and will fail the test properly. I tried taking smtp out of the async block and it...
Read more >
The SAML assertion isn't encrypted. - ComponentSpace
But when we set it to WantAssertionEncrypted="true", we got the error saying "The SAML assertion isn't encrypted." Also from the ComponentSpace SAML ...
Read more >
Assert using XPath in XML contained in CDATA
Hi Ole, I am trying to add XPath assertions to validate the data that I am getting in a ... but no corporate/government...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found