I am trying to traverse through a list of elements and want to assert that the body includes either of the 2 values. I am trying to use the following but it only lets me assert one value.
expect(cellText).includes(toDateFormat);
How can I make an assertion that allows me to assert multiple values having OR condition?
You could use Chai's satisfy to accomplish this.
Invokes the given matcher function with the target being passed as the first argument, and asserts that the value returned is truthy.
expect(cellText).to.satisfy(function(text) {
return text.includes(toDateFormat) || text.includes(otherFormatVariable);
})
If you have a long list of potential expected values, you could simplify this by having those values in an array, and using array.filter()
to find instances of the actual text value in the expected text value, and returning the length of the filtered array.
const expected = ['foo', 'bar', 'baz']
expect(cellText).to.satisfy(function(text) {
return expected.filter((x) => cellText.includes(x)).length
});