jasmine.allOf AsymmetricEqualityTester

New asymmetric equality tester that accepts a variable number of arguments, and will pass if all of them evaluate as being equal to the input value.
Includes unit tests
This commit is contained in:
Jonah Bron
2025-10-23 12:52:52 -07:00
parent 9a67c4e24d
commit 75658e0566
4 changed files with 104 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
getJasmineRequireObj().AllOf = function(j$) {
function AllOf() {
const expectedValues = Array.from(arguments);
if (expectedValues.length === 0) {
throw new TypeError(
'jasmine.allOf() expects at least one argument to be passed.'
);
}
this.expectedValues = expectedValues;
}
AllOf.prototype.asymmetricMatch = function(other, matchersUtil) {
for (const expectedValue of this.expectedValues) {
if (!matchersUtil.equals(other, expectedValue)) {
return false;
}
}
return true;
};
AllOf.prototype.jasmineToString = function(pp) {
return '<jasmine.allOf(' + pp(this.expectedValues) + ')>';
};
return AllOf;
};