Cannot get text as in GUI

101 Views Asked by At

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?

2

There are 2 best solutions below

5
On

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.

0
On

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')
  })