diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index 3a8054a7..1e1140e2 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -413,6 +413,53 @@ describe("matchersUtil", function() { var setB = new Set([6, 3]); expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false); }); + + describe("when running in an environment with array polyfills", function() { + // IE 8 doesn't support `definePropery` on non-DOM nodes + if (jasmine.getEnv().ieVersion < 9) { return; } + + var findIndexDescriptor = Object.getOwnPropertyDescriptor(Array.prototype, 'findIndex'); + if (!findIndexDescriptor) { + return; + } + + beforeEach(function() { + Object.defineProperty(Array.prototype, 'findIndex', { + enumerable: true, + value: function (predicate) { + if (this === null) { + throw new TypeError('Array.prototype.findIndex called on null or undefined'); + } + + if (typeof predicate !== 'function') { + throw new TypeError('predicate must be a function'); + } + + var list = Object(this); + var length = list.length >>> 0; + var thisArg = arguments[1]; + var value; + + for (var i = 0; i < length; i++) { + value = list[i]; + if (predicate.call(thisArg, value, i, list)) { + return i; + } + } + + return -1; + } + }); + }); + + afterEach(function() { + Object.defineProperty(Array.prototype, 'findIndex', findIndexDescriptor); + }); + + it("passes when there's an array polyfill", function() { + expect(['foo']).toEqual(['foo']); + }); + }); }); describe("contains", function() { diff --git a/src/core/matchers/matchersUtil.js b/src/core/matchers/matchersUtil.js index 28314891..3aba3f0f 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -327,7 +327,7 @@ getJasmineRequireObj().matchersUtil = function(j$) { } var extraKeys = []; - for (var i in allKeys) { + for (var i = 0; i < allKeys.length; i++) { if (!allKeys[i].match(/^[0-9]+$/)) { extraKeys.push(allKeys[i]); }