I'm trying to do some Cypress assertions to see whether or not it contains one or another string. It can be in English or Spanish, so either one should pass the test.
cy.get(el).should('contain', 'submit').or('contain', 'enviar')
obviously doesnt work.
const runout = ['submit', 'enviar']
const el = '[data-test=btn-submit]'
function checkArray(arr, el) {
for(let i = 0; i < arr.length; i++) {
if(cy.get(el).contains(arr[i])) {
return true
} else {
if (i === arr.length) {
return false
}
}
}
}
cy.expect(checkArray(runout,el)).to.be.true
fails the test, still checking both strings.
You can try a regular expression, see contains#Regular-Expression.
See this question Regular expression containing one word or another for some formats
I think something as simple as this will do it,
cy.get(el).contains(/submit|enviar/g)
Experiment first on Regex101 or similar online tester.
Maybe build it with
const runout = ['submit', 'enviar']
const regex = new RegExp(`${runout.join('|')}`, 'g')
cy.get(el).contains(regex)