mapContaining and setContaining asymmetric matchers

This commit is contained in:
Olga Kozlova
2019-08-03 22:14:17 +03:00
parent 385ad33f60
commit b01d86840a
9 changed files with 479 additions and 1 deletions

View File

@@ -133,5 +133,24 @@ getJasmineRequireObj().util = function(j$) {
};
})();
function StopIteration() {}
StopIteration.prototype = Object.create(Error.prototype);
StopIteration.prototype.constructor = StopIteration;
// useful for maps and sets since `forEach` is the only IE11-compatible way to iterate them
util.forEachBreakable = function(iterable, iteratee) {
function breakLoop() {
throw new StopIteration();
}
try {
iterable.forEach(function(value, key) {
iteratee(breakLoop, value, key, iterable);
});
} catch (error) {
if (!(error instanceof StopIteration)) throw error;
}
};
return util;
};