Files
jasmine/src/core/ObjectContaining.js
Greg Cobb and JR Boyens 8c1881053c Resolve remaining test issues
2013-07-22 11:57:47 -07:00

35 lines
1.4 KiB
JavaScript

getJasmineRequireObj().ObjectContaining = function(j$) {
function ObjectContaining(sample) {
this.sample = sample;
}
ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) {
if (typeof(this.sample) !== "object") { throw new Error("You must provide an object to objectContaining, not '"+this.sample+"'."); }
mismatchKeys = mismatchKeys || [];
mismatchValues = mismatchValues || [];
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)) {
mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
}
else if (!j$.matchersUtil.equals(this.sample[property], other[property])) {
mismatchValues.push("'" + property + "' was '" + (other[property] ? j$.util.htmlEscape(other[property].toString()) : other[property]) + "' in actual, but was '" + (this.sample[property] ? j$.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + "' in expected.");
}
}
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
};
ObjectContaining.prototype.jasmineToString = function() {
return "<jasmine.objectContaining(" + j$.pp(this.sample) + ")>";
};
return ObjectContaining;
};