I have the following code
checkLocationsInTable(location) {
cy.datacy('locationCell').each(($el) => {
cy.wrap($el).invoke('text').should('match', /Cheltenham \(Remote\)|Home/i)
}).then(($els) => {
cy.datacy('searchResults').should('contain', $els.length.toString())
})
}
Which works as I want, however I would like to remove the hardcoded regex with one created from the value contained in the location variable.
The location variable will consist of an array of text, long the lines of this
['Cheltenham (Remote)', 'Home'])
I tried this
checkLocationsInTable(location) {
let output = location.join('|').replaceAll("(", "/(").replaceAll(")", "/)")
cy.datacy('locationCell').each(($el) => {
cy.wrap($el).invoke('text').should('match', new RegExp(output), 'g')
}).then(($els) => {
cy.datacy('searchResults').should('contain', $els.length.toString())
})
}
But it doesnβt work.