matchersUtil.equals() does not expect a matcher as its first argument, so send the "actual" value first and the "expected" value second.
35 lines
1.4 KiB
JavaScript
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(other[property], this.sample[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;
|
|
};
|