Search code examples
cucumbercypressbdd

How to remove \n\t in Cypress?


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?


Solution

  • 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