Cypress assert text while ignoring soft hyphens

345 Views Asked by At

I'm trying to E2E test a web application using cypress/cucumber. The page I'm testing has a H1 title I want to check the contents of. Normally I would use something like cy.get('H1').should('contain.text', 'some longpagetitle')

However there is a soft hyphen (­ to be precise) in the title. So the above line fails.. I rather not put the soft hyphen in my assertion.

Is it possible to assert text while ignoring soft hyphens?

1

There are 1 best solutions below

0
Fody On BEST ANSWER

Apply a replace to the text,

<h1>extra&shy;ordinarily lond&shy;winded text</h1>
cy.get('h1')
  .invoke('text')
  .then(text => text.replace(/\u00AD/g,''))
  .should('eq', 'extraordinarily longwinded text')    // passes