The Problem:
I have an array of promises which is resolved to an array of strings. Now the test should pass if at least one of the strings matc
You could simply use map
to get a list of boolean
and then assert the result with toContain(true)
:
var all = protractor.promise.all;
var map = protractor.promise.map;
expect(map(all([text1, text2, text3]), RegExp.prototype.test, /expression/)).toContain(true);
You could also use a custom matcher:
expect(all([text1, text2, text3])).toContainPattern(/expression/);
And the custom matcher declared in beforeEach
:
beforeEach(function() {
jasmine.addMatchers({
toContainPattern: function() {
return {
compare: function(actual, regex) {
return {
pass: actual.some(RegExp.prototype.test, regex),
message: "Expected [" + actual + "] to have one or more match with " + regex
};
}
};
}
});
});