Skip to content

Commit

Permalink
add jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed May 20, 2024
1 parent c58cbed commit 6f7d42a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3933,7 +3933,14 @@ Assertion.addProperty('finite', function(msg) {
)
});

function compare(expected, actual) {
/**
* A subset-aware compare function
*
* @param {unknown} expected
* @param {unknown} actual
* @returns {void}
*/
function compareSubset(expected, actual) {
if (expected === actual) {
return true;
}
Expand All @@ -3954,7 +3961,7 @@ function compare(expected, actual) {
var aa = Array.prototype.slice.call(actual);
return expected.every(function (exp) {
return aa.some(function (act) {
return compare(exp, act);
return compareSubset(exp, act);
});
});
}
Expand All @@ -3971,7 +3978,7 @@ function compare(expected, actual) {
var eo = expected[key];
var ao = actual[key];
if (typeof eo === 'object' && eo !== null && ao !== null) {
return compare(eo, ao);
return compareSubset(eo, ao);
}
if (typeof eo === 'function') {
return eo(ao);
Expand All @@ -3985,7 +3992,7 @@ Assertion.addMethod('containSubset', function (expected) {
const showDiff = config.showDiff;

this.assert(
compare(expected, actual),
compareSubset(expected, actual),
'expected #{act} to contain subset #{exp}',
'expected #{act} to not contain subset #{exp}',
expected,
Expand Down

0 comments on commit 6f7d42a

Please sign in to comment.