Check for ObjectContaining on either side of equality.

- Also clean up `undefined` check.

Fixes #682
This commit is contained in:
slackersoft
2014-12-16 17:05:32 -08:00
parent 6bd98cb2ab
commit ea88023553
5 changed files with 28 additions and 14 deletions

View File

@@ -7,13 +7,9 @@ getJasmineRequireObj().ObjectContaining = function(j$) {
ObjectContaining.prototype.asymmetricMatch = function(other) {
if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
var hasKey = function(obj, keyName) {
return obj !== null && !j$.util.isUndefined(obj[keyName]);
};
for (var property in this.sample) {
if (!hasKey(other, property) && hasKey(this.sample, property) ||
!j$.matchersUtil.equals(other[property], this.sample[property])) {
if (!Object.prototype.hasOwnProperty.call(other, property) ||
!j$.matchersUtil.equals(this.sample[property], other[property])) {
return false;
}
}

View File

@@ -71,6 +71,10 @@ getJasmineRequireObj().matchersUtil = function(j$) {
return b.asymmetricMatch(a);
}
if (a instanceof j$.ObjectContaining) {
return a.asymmetricMatch(b);
}
if (b instanceof j$.ObjectContaining) {
return b.asymmetricMatch(a);
}