Just check if either side implements asymmetricMatch
- Don't explicitly look for `Any` or `ObjectContaining` [#82295210]
This commit is contained in:
@@ -2235,6 +2235,10 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
function isAsymmetric(obj) {
|
||||
return obj && j$.isA_('Function', obj.asymmetricMatch);
|
||||
}
|
||||
|
||||
// Equality function lovingly adapted from isEqual in
|
||||
// [Underscore](http://underscorejs.org)
|
||||
function eq(a, b, aStack, bStack, customTesters) {
|
||||
@@ -2247,19 +2251,11 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
}
|
||||
}
|
||||
|
||||
if (a instanceof j$.Any) {
|
||||
if (isAsymmetric(a)) {
|
||||
return a.asymmetricMatch(b);
|
||||
}
|
||||
|
||||
if (b instanceof j$.Any) {
|
||||
return b.asymmetricMatch(a);
|
||||
}
|
||||
|
||||
if (a instanceof j$.ObjectContaining) {
|
||||
return a.asymmetricMatch(b);
|
||||
}
|
||||
|
||||
if (b instanceof j$.ObjectContaining) {
|
||||
if (isAsymmetric(b)) {
|
||||
return b.asymmetricMatch(a);
|
||||
}
|
||||
|
||||
|
||||
@@ -198,6 +198,20 @@ describe("matchersUtil", function() {
|
||||
expect(j$.matchersUtil.equals(containing, obj)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when an asymmetric equality tester returns true", function() {
|
||||
var tester = { asymmetricMatch: function(other) { return true; } };
|
||||
|
||||
expect(j$.matchersUtil.equals(false, tester)).toBe(true);
|
||||
expect(j$.matchersUtil.equals(tester, false)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when an asymmetric equality tester returns false", function() {
|
||||
var tester = { asymmetricMatch: function(other) { return false; } };
|
||||
|
||||
expect(j$.matchersUtil.equals(true, tester)).toBe(false);
|
||||
expect(j$.matchersUtil.equals(tester, true)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes when a custom equality matcher returns true", function() {
|
||||
var tester = function(a, b) { return true; };
|
||||
|
||||
|
||||
@@ -51,6 +51,10 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
function isAsymmetric(obj) {
|
||||
return obj && j$.isA_('Function', obj.asymmetricMatch);
|
||||
}
|
||||
|
||||
// Equality function lovingly adapted from isEqual in
|
||||
// [Underscore](http://underscorejs.org)
|
||||
function eq(a, b, aStack, bStack, customTesters) {
|
||||
@@ -63,19 +67,11 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
}
|
||||
}
|
||||
|
||||
if (a instanceof j$.Any) {
|
||||
if (isAsymmetric(a)) {
|
||||
return a.asymmetricMatch(b);
|
||||
}
|
||||
|
||||
if (b instanceof j$.Any) {
|
||||
return b.asymmetricMatch(a);
|
||||
}
|
||||
|
||||
if (a instanceof j$.ObjectContaining) {
|
||||
return a.asymmetricMatch(b);
|
||||
}
|
||||
|
||||
if (b instanceof j$.ObjectContaining) {
|
||||
if (isAsymmetric(b)) {
|
||||
return b.asymmetricMatch(a);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user