sonia sharma sonia sharma - 27 days ago 15
Javascript Question

match multiple values with one expected values, always try to match only first value and fails

I am using bellow mentioned code to compare multiple values with one expected values and if the text matches with anyone of them my test should pass :

Promise.all([Summ,Desc,Comment]).then(function(values){
console.log("values = " +values);
expect(values[0]||values[1]||values[2]).toMatch('searchtxt');
});


But with this code it always try to match first (values[0]), if this does not match then my test will fail.

How can I change it so that protractor looks for all 3 values and then if anyone of them matches my test should pass.

Answer

if anyone of them matches my test should pass

In this case, you don't need anything special, just concatenate the values:

expect(values[0] + values[1] + values[2]).toMatch('searchtxt');

Please also see the follow-up to your problem here: