diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 58887e75..d084a3d9 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -5493,8 +5493,13 @@ getJasmineRequireObj().MatchersUtil = function(j$) { (!!haystack && !haystack.indexOf) ) { for (var i = 0; i < haystack.length; i++) { - if (this.equals(haystack[i], needle, customTesters)) { - return true; + try { + this.suppressDeprecation_ = true; + if (this.equals(haystack[i], needle, customTesters)) { + return true; + } + } finally { + this.suppressDeprecation_ = false; } } return false; @@ -5613,7 +5618,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) { if (isDiffBuilder(customTestersOrDiffBuilder)) { diffBuilder = customTestersOrDiffBuilder; } else { - if (customTestersOrDiffBuilder) { + if (customTestersOrDiffBuilder && !this.suppressDeprecation_) { j$.getEnv().deprecated( 'Passing custom equality testers ' + 'to MatchersUtil#equals is deprecated. ' + diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index 3d86f01d..7fc9fc85 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -1235,6 +1235,22 @@ describe('matchersUtil', function() { expect(matchersUtil.contains([1, 2], 3)).toBe(true); }); + it('logs a single deprecation warning when custom equality testers are passed', function() { + // TODO: remove this in the next major release. + var matchersUtil = new jasmineUnderTest.MatchersUtil(), + deprecated = spyOn(jasmineUnderTest.getEnv(), 'deprecated'); + + matchersUtil.contains([0], 0, []); + + expect(deprecated).toHaveBeenCalledOnceWith( + jasmine.stringMatching( + 'Passing custom equality testers ' + + 'to MatchersUtil#contains is deprecated. ' + + 'See for details.' + ) + ); + }); + it('fails when actual is undefined', function() { var matchersUtil = new jasmineUnderTest.MatchersUtil(); expect(matchersUtil.contains(undefined, 'A')).toBe(false); diff --git a/src/core/matchers/matchersUtil.js b/src/core/matchers/matchersUtil.js index bba9797c..f8819549 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -51,8 +51,13 @@ getJasmineRequireObj().MatchersUtil = function(j$) { (!!haystack && !haystack.indexOf) ) { for (var i = 0; i < haystack.length; i++) { - if (this.equals(haystack[i], needle, customTesters)) { - return true; + try { + this.suppressDeprecation_ = true; + if (this.equals(haystack[i], needle, customTesters)) { + return true; + } + } finally { + this.suppressDeprecation_ = false; } } return false; @@ -171,7 +176,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) { if (isDiffBuilder(customTestersOrDiffBuilder)) { diffBuilder = customTestersOrDiffBuilder; } else { - if (customTestersOrDiffBuilder) { + if (customTestersOrDiffBuilder && !this.suppressDeprecation_) { j$.getEnv().deprecated( 'Passing custom equality testers ' + 'to MatchersUtil#equals is deprecated. ' +