30 lines
860 B
JavaScript
30 lines
860 B
JavaScript
getJasmineRequireObj().ObjectContaining = function(j$) {
|
|
|
|
function ObjectContaining(sample) {
|
|
this.sample = sample;
|
|
}
|
|
|
|
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])) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
ObjectContaining.prototype.jasmineToString = function() {
|
|
return '<jasmine.objectContaining(' + j$.pp(this.sample) + ')>';
|
|
};
|
|
|
|
return ObjectContaining;
|
|
};
|