How to remove \n\t in Cypress?

Ingridd Brito

I am using BDD with Cypress. The element I want to check is

enter image description here

So this element is on the PageObject:

allowPriceEmbeddedBarcodeAtPOS(){       
   return cy.get('im-data-table.hydrated').shadow().find('tr:nth-child(2) > td:nth-child(2)') 
}

And on the Step Definition file I have:

And("Global Configuration is set true", () => {
    platformadmin.allowPriceEmbeddedBarcodeAtPOS().should('contains.text','{"AllowPriceEmbeddedBarcodeAtPOS": true}')
    })

But when I run cypress it founds the element with \n\t

enter image description here

Any ideas how can I remove this?

Fody

You can use a regex with \s to remove all whitespace

platformadmin.allowPriceEmbeddedBarcodeAtPOS()
  .then($el => $el.text().replace(/\s/g, ''))
  .should('eq','{"AllowPriceEmbeddedBarcodeAtPOS":true}')

Ref Cypress recipe have-attr-assertion

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324270767&siteId=291194637