diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 5ab5fec7..0753077a 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2902,10 +2902,7 @@ getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) { matchersUtil, customEqualityTesters ) { - var self = Object.create(matchersUtil), - props, - i, - k; + var self = Object.create(matchersUtil); copyAndDeprecate(self, customEqualityTesters, 'length'); @@ -2913,18 +2910,30 @@ getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) { copyAndDeprecate(self, customEqualityTesters, i); } - var props = arrayProps(); + // Avoid copying array props if we've previously done so, + // to avoid triggering our own deprecation warnings. + if (!self.isAsymmetricEqualityTesterArgCompatShim_) { + copyAndDeprecateArrayMethods(self); + } + + self.isAsymmetricEqualityTesterArgCompatShim_ = true; + return self; + } + + function copyAndDeprecateArrayMethods(dest) { + var props = arrayProps(), + i, + k; for (i = 0; i < props.length; i++) { k = props[i]; + // Skip length (dealt with above), and anything that collides with // MatchesUtil e.g. an Array.prototype.contains method added by user code - if (k !== 'length' && !self[k]) { - copyAndDeprecate(self, Array.prototype, k); + if (k !== 'length' && !dest[k]) { + copyAndDeprecate(dest, Array.prototype, k); } } - - return self; } function copyAndDeprecate(dest, src, propName) { diff --git a/spec/core/asymmetricEqualityTesterArgCompatShimSpec.js b/spec/core/asymmetricEqualityTesterArgCompatShimSpec.js index 02cccbd4..b9f5ad25 100644 --- a/spec/core/asymmetricEqualityTesterArgCompatShimSpec.js +++ b/spec/core/asymmetricEqualityTesterArgCompatShimSpec.js @@ -181,4 +181,18 @@ describe('asymmetricEqualityTesterArgCompatShim', function() { }); }); }); + + describe('When the matchersUtil is already an asymmetricEqualityTesterArgCompatShim', function() { + it('does not trigger any deprecations', function() { + var shim1 = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim( + {}, + [] + ); + spyOn(jasmineUnderTest.getEnv(), 'deprecated'); + + jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(shim1, []); + + expect(jasmineUnderTest.getEnv().deprecated).not.toHaveBeenCalled(); + }); + }); }); diff --git a/src/core/asymmetricEqualityTesterArgCompatShim.js b/src/core/asymmetricEqualityTesterArgCompatShim.js index 7589e021..7ba21831 100644 --- a/src/core/asymmetricEqualityTesterArgCompatShim.js +++ b/src/core/asymmetricEqualityTesterArgCompatShim.js @@ -51,10 +51,7 @@ getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) { matchersUtil, customEqualityTesters ) { - var self = Object.create(matchersUtil), - props, - i, - k; + var self = Object.create(matchersUtil); copyAndDeprecate(self, customEqualityTesters, 'length'); @@ -62,18 +59,30 @@ getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) { copyAndDeprecate(self, customEqualityTesters, i); } - var props = arrayProps(); + // Avoid copying array props if we've previously done so, + // to avoid triggering our own deprecation warnings. + if (!self.isAsymmetricEqualityTesterArgCompatShim_) { + copyAndDeprecateArrayMethods(self); + } + + self.isAsymmetricEqualityTesterArgCompatShim_ = true; + return self; + } + + function copyAndDeprecateArrayMethods(dest) { + var props = arrayProps(), + i, + k; for (i = 0; i < props.length; i++) { k = props[i]; + // Skip length (dealt with above), and anything that collides with // MatchesUtil e.g. an Array.prototype.contains method added by user code - if (k !== 'length' && !self[k]) { - copyAndDeprecate(self, Array.prototype, k); + if (k !== 'length' && !dest[k]) { + copyAndDeprecate(dest, Array.prototype, k); } } - - return self; } function copyAndDeprecate(dest, src, propName) {