This allows custom equality testers to affect asymmetric matches. This avoid suprises when combining addCustomEqualityTester with objectContaining or arrayContaining. Closes #1138
26 lines
786 B
JavaScript
26 lines
786 B
JavaScript
getJasmineRequireObj().ArrayContaining = function(j$) {
|
|
function ArrayContaining(sample) {
|
|
this.sample = sample;
|
|
}
|
|
|
|
ArrayContaining.prototype.asymmetricMatch = function(other, customTesters) {
|
|
var className = Object.prototype.toString.call(this.sample);
|
|
if (className !== '[object Array]') { throw new Error('You must provide an array to arrayContaining, not \'' + this.sample + '\'.'); }
|
|
|
|
for (var i = 0; i < this.sample.length; i++) {
|
|
var item = this.sample[i];
|
|
if (!j$.matchersUtil.contains(other, item, customTesters)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
ArrayContaining.prototype.jasmineToString = function () {
|
|
return '<jasmine.arrayContaining(' + jasmine.pp(this.sample) +')>';
|
|
};
|
|
|
|
return ArrayContaining;
|
|
};
|