Squashed matchers refactor - matchers now unit-testable apart from Expectation and Spec.
This commit is contained in:
32
src/core/ObjectContaining.js
Normal file
32
src/core/ObjectContaining.js
Normal file
@@ -0,0 +1,32 @@
|
||||
getJasmineRequireObj().ObjectContaining = function(j$) {
|
||||
|
||||
function ObjectContaining(sample) {
|
||||
this.sample = sample;
|
||||
}
|
||||
|
||||
ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) {
|
||||
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], mismatchKeys, mismatchValues)) {
|
||||
mismatchValues.push("'" + property + "' was '" + (other[property] ? j$.util.htmlEscape(other[property].toString()) : other[property]) + "' in expected, but was '" + (this.sample[property] ? j$.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + "' in actual.");
|
||||
}
|
||||
}
|
||||
|
||||
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
|
||||
};
|
||||
|
||||
ObjectContaining.prototype.jasmineToString = function() {
|
||||
return "<jasmine.objectContaining(" + j$.pp(this.sample) + ")>";
|
||||
};
|
||||
|
||||
return ObjectContaining;
|
||||
};
|
||||
Reference in New Issue
Block a user