Fixed diffs involving jasmine.objectContaining
This commit is contained in:
@@ -111,6 +111,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
return false;
|
||||
};
|
||||
|
||||
j$.isAsymmetricEqualityTester_ = function(obj) {
|
||||
return obj && j$.isA_('Function', obj.asymmetricMatch);
|
||||
};
|
||||
|
||||
j$.getType_ = function(value) {
|
||||
return Object.prototype.toString.apply(value);
|
||||
};
|
||||
|
||||
@@ -21,8 +21,9 @@ getJasmineRequireObj().DiffBuilder = function (j$) {
|
||||
|
||||
mismatches.traverse(function (path, isLeaf, formatter) {
|
||||
var actualCustom, expectedCustom, useCustom,
|
||||
actual = path.dereference(actualRoot),
|
||||
expected = path.dereference(expectedRoot);
|
||||
derefResult = dereferencePath(path, actualRoot, expectedRoot, prettyPrinter),
|
||||
actual = derefResult.actual,
|
||||
expected = derefResult.expected;
|
||||
|
||||
if (formatter) {
|
||||
messages.push(formatter(actual, expected, path, prettyPrinter));
|
||||
@@ -69,4 +70,22 @@ getJasmineRequireObj().DiffBuilder = function (j$) {
|
||||
'.';
|
||||
}
|
||||
};
|
||||
|
||||
function dereferencePath(objectPath, actual, expected, pp) {
|
||||
var i, asymmetricResult
|
||||
|
||||
for (i = 0; i < objectPath.components.length; i++) {
|
||||
actual = actual[objectPath.components[i]];
|
||||
expected = expected[objectPath.components[i]];
|
||||
|
||||
if (j$.isAsymmetricEqualityTester_(expected) && j$.isFunction_(expected.valuesForDiff_)) {
|
||||
var asymmetricResult = expected.valuesForDiff_(actual, pp);
|
||||
expected = asymmetricResult.self;
|
||||
actual = asymmetricResult.other;
|
||||
}
|
||||
}
|
||||
|
||||
return {actual: actual, expected: expected};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -11,16 +11,6 @@ getJasmineRequireObj().ObjectPath = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
ObjectPath.prototype.dereference = function(obj) {
|
||||
var i;
|
||||
|
||||
for (i = 0; i < this.components.length; i++) {
|
||||
obj = obj[this.components[i]];
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
ObjectPath.prototype.add = function(component) {
|
||||
return new ObjectPath(this.components.concat([component]));
|
||||
};
|
||||
|
||||
@@ -78,13 +78,9 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
return message + '.';
|
||||
};
|
||||
|
||||
function isAsymmetric(obj) {
|
||||
return obj && j$.isA_('Function', obj.asymmetricMatch);
|
||||
}
|
||||
|
||||
MatchersUtil.prototype.asymmetricDiff_ = function(a, b, aStack, bStack, customTesters, diffBuilder) {
|
||||
if (j$.isFunction_(b.valuesForDiff_)) {
|
||||
var values = b.valuesForDiff_(a);
|
||||
var values = b.valuesForDiff_(a, this.pp);
|
||||
this.eq_(values.other, values.self, aStack, bStack, customTesters, diffBuilder);
|
||||
} else {
|
||||
diffBuilder.recordMismatch();
|
||||
@@ -92,8 +88,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
};
|
||||
|
||||
MatchersUtil.prototype.asymmetricMatch_ = function(a, b, aStack, bStack, customTesters, diffBuilder) {
|
||||
var asymmetricA = isAsymmetric(a),
|
||||
asymmetricB = isAsymmetric(b),
|
||||
var asymmetricA = j$.isAsymmetricEqualityTester_(a),
|
||||
asymmetricB = j$.isAsymmetricEqualityTester_(b),
|
||||
shim = j$.asymmetricEqualityTesterArgCompatShim(this, customTesters),
|
||||
result;
|
||||
|
||||
@@ -104,8 +100,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
if (asymmetricA) {
|
||||
result = a.asymmetricMatch(b, shim);
|
||||
if (!result) {
|
||||
// TODO: Do we want to build an asymmetric diff when the actual was an
|
||||
// asymmeteric equality tester? Might be confusing.
|
||||
diffBuilder.recordMismatch();
|
||||
}
|
||||
return result;
|
||||
@@ -328,7 +322,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
// Only use the cmpKey when one of the keys is asymmetric and the corresponding key matches,
|
||||
// otherwise explicitly look up the mapKey in the other Map since we want keys with unique
|
||||
// obj identity (that are otherwise equal) to not match.
|
||||
if (isAsymmetric(mapKey) || isAsymmetric(cmpKey) &&
|
||||
if (j$.isAsymmetricEqualityTester_(mapKey) || j$.isAsymmetricEqualityTester_(cmpKey) &&
|
||||
this.eq_(mapKey, cmpKey, aStack, bStack, customTesters, j$.NullDiffBuilder())) {
|
||||
mapValueB = b.get(cmpKey);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user