Reputation: 69
Is there any way we could do a assert of a partial word of a value from an arraylist using expect of Protractor ?
I have tried the below method which returns me a failure. Any suggestions or corrections to the below logic ?
var results=['Hello','Side Navigation','twice','jumbo'];
expect(results.indexOf('Navigation')!=-1).toBeTruthy();
Failures:
Message:
[31m Expected false to be truthy.[0m
Stack:
Error: Failed expectation
Upvotes: 0
Views: 296
Reputation: 1288
You can compare the items in the array using a plain old javascript function:
var arrayContainsText = function(array, text) {
return array.some(function(item) {
return new RegExp(text).test(item);
});
});
var results=['Hello','Side Navigation','twice','jumbo'];
var text = 'Navigation';
expect(arrayContainsText(results, text)).toBeTruthy();
Upvotes: 1