ObjectContaining matches prototype properties

[#769]
This commit is contained in:
Greg Cobb and Gregg Van Hove
2015-02-05 14:06:52 -08:00
parent e1249ac89a
commit 69956bf8f6
3 changed files with 81 additions and 2 deletions

View File

@@ -4,11 +4,35 @@ getJasmineRequireObj().ObjectContaining = function(j$) {
this.sample = sample;
}
function getPrototype(obj) {
if (Object.getPrototypeOf) {
return Object.getPrototypeOf(obj);
}
if (obj.constructor.prototype == obj) {
return null;
}
return obj.constructor.prototype;
}
function hasProperty(obj, property) {
if (!obj) {
return false;
}
if (Object.prototype.hasOwnProperty.call(obj, property)) {
return true;
}
return hasProperty(getPrototype(obj), property);
}
ObjectContaining.prototype.asymmetricMatch = function(other) {
if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
for (var property in this.sample) {
if (!Object.prototype.hasOwnProperty.call(other, property) ||
if (!hasProperty(other, property) ||
!j$.matchersUtil.equals(this.sample[property], other[property])) {
return false;
}