diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 65146cf8..cf4191b5 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -279,7 +279,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { }; j$.isAsymmetricEqualityTester_ = function(obj) { - return obj && j$.isA_('Function', obj.asymmetricMatch); + return obj ? j$.isA_('Function', obj.asymmetricMatch) : false; }; j$.getType_ = function(value) { @@ -4494,13 +4494,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) { MatchersUtil.prototype.asymmetricMatch_ = function(a, b, aStack, bStack, customTesters, diffBuilder) { var asymmetricA = j$.isAsymmetricEqualityTester_(a), asymmetricB = j$.isAsymmetricEqualityTester_(b), - shim = j$.asymmetricEqualityTesterArgCompatShim(this, customTesters), + shim, result; - if (asymmetricA && asymmetricB) { + if (asymmetricA === asymmetricB) { return undefined; } + shim = j$.asymmetricEqualityTesterArgCompatShim(this, customTesters); + if (asymmetricA) { result = a.asymmetricMatch(b, shim); if (!result) { diff --git a/spec/core/baseSpec.js b/spec/core/baseSpec.js index 07f94e19..4fce2254 100644 --- a/spec/core/baseSpec.js +++ b/spec/core/baseSpec.js @@ -30,4 +30,25 @@ describe('base helpers', function() { }, 100); }); }); + + describe('isAsymmetricEqualityTester_', function() { + it('returns false when the argument is falsy', function() { + expect(jasmineUnderTest.isAsymmetricEqualityTester_(null)).toBe(false); + }); + + it('returns false when the argument does not have a asymmetricMatch property', function() { + var obj = {}; + expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(false); + }); + + it("returns false when the argument's asymmetricMatch is not a function", function() { + var obj = { asymmetricMatch: 'yes' }; + expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(false); + }); + + it("returns true when the argument's asymmetricMatch is a function", function() { + var obj = { asymmetricMatch: function() {} }; + expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(true); + }); + }); }); diff --git a/src/core/base.js b/src/core/base.js index 37aa692e..e86a12c8 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -112,7 +112,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { }; j$.isAsymmetricEqualityTester_ = function(obj) { - return obj && j$.isA_('Function', obj.asymmetricMatch); + return obj ? j$.isA_('Function', obj.asymmetricMatch) : false; }; j$.getType_ = function(value) { diff --git a/src/core/matchers/matchersUtil.js b/src/core/matchers/matchersUtil.js index 6fa812bf..8ee6368e 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -90,13 +90,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) { MatchersUtil.prototype.asymmetricMatch_ = function(a, b, aStack, bStack, customTesters, diffBuilder) { var asymmetricA = j$.isAsymmetricEqualityTester_(a), asymmetricB = j$.isAsymmetricEqualityTester_(b), - shim = j$.asymmetricEqualityTesterArgCompatShim(this, customTesters), + shim, result; - if (asymmetricA && asymmetricB) { + if (asymmetricA === asymmetricB) { return undefined; } + shim = j$.asymmetricEqualityTesterArgCompatShim(this, customTesters); + if (asymmetricA) { result = a.asymmetricMatch(b, shim); if (!result) {