Add asymmetric equality tester to match a string against a regexp
- Also move the asymmetric testers into their own dir for easier locating. [#58120558] Fix #243
This commit is contained in:
25
src/core/asymmetric_equality/ObjectContaining.js
Normal file
25
src/core/asymmetric_equality/ObjectContaining.js
Normal file
@@ -0,0 +1,25 @@
|
||||
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+'\'.'); }
|
||||
|
||||
for (var property in this.sample) {
|
||||
if (!Object.prototype.hasOwnProperty.call(other, property) ||
|
||||
!j$.matchersUtil.equals(this.sample[property], other[property])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
ObjectContaining.prototype.jasmineToString = function() {
|
||||
return '<jasmine.objectContaining(' + j$.pp(this.sample) + ')>';
|
||||
};
|
||||
|
||||
return ObjectContaining;
|
||||
};
|
||||
Reference in New Issue
Block a user