diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index c88a758d..7dfd4fb1 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -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; } @@ -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); }); }); } @@ -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); @@ -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,