1

I have some amounts which I need to display. The amounts needs to be hovered and then they would show.

For example an amount may be +123 456,33 but in the code it is showing as like +123NNSP456,33. Now when I write my test, I am having to put

cy.get('.total-month').should('contain.text','+123NNSP456,33') 

so that the test passed. If I test for what is being showed in the GUI like this

cy.get('.total-month').should('contain.text','+123 456,33') 

it is not identifying the amount.

This is the html:

enter image description here

What am i doing wrong?

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
ZombiePie
  • 299
  • 1
  • 4
  • 14
  • Please [edit] this question to type the text from the image so that it can be read on all devices, quoted, edited, and found through search. As it stands now, [your image makes it hard to answer your question or for people with related issues to find your question](//meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question). See the [formatting documentation](/editing-help) for tips to make your text appear nicely without resorting to images. – Stephen Ostermiller Oct 15 '21 at 12:58

2 Answers2

4

Using a similar strategy to Jennifer's answer, you can use invoke to replace the text value.

cy.get('.total-month')
  .invoke('text')
  .invoke('replace', 'NNSP', ' ')
  .should('contains', '+123 456,33');

The tl;dr is that your character is interpreted as NNSP. Replacing that with a traditional whitespace character should solve your problem.

agoff
  • 5,818
  • 1
  • 7
  • 20
0

You can also use the replace method to replace NNSP with an empty string.

cy.get('.total-month')
  .invoke('text')
  .then((text) => {
    expect(text.trim().replace('NNSP', '')).to.equal('+123456,33')
  })
Alapan Das
  • 17,144
  • 3
  • 29
  • 52