2

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?

Fody
  • 23,754
  • 3
  • 20
  • 37
Mike Bovenlander
  • 5,236
  • 5
  • 28
  • 47

1 Answers1

2

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
Fody
  • 23,754
  • 3
  • 20
  • 37