From cfc76f269987851160ccc71a91178056f5df25ea Mon Sep 17 00:00:00 2001 From: Enes Uygur Date: Fri, 23 Oct 2026 16:53:21 +0300 Subject: [PATCH] fix: clear prop for getter calls with a message in assert delta helpers --- lib/chai/interface/assert.js | 7 +++++++ test/assert.js | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js index 4fd39807..fd448ecf 100644 --- a/lib/chai/interface/assert.js +++ b/lib/chai/interface/assert.js @@ -2614,6 +2614,7 @@ assert.changesBy = function (fn, obj, prop, delta, msg) { let tmpMsg = delta; delta = prop; msg = tmpMsg; + prop = null; } else if (arguments.length === 3) { delta = prop; prop = null; @@ -2675,6 +2676,7 @@ assert.changesButNotBy = function (fn, obj, prop, delta, msg) { let tmpMsg = delta; delta = prop; msg = tmpMsg; + prop = null; } else if (arguments.length === 3) { delta = prop; prop = null; @@ -2735,6 +2737,7 @@ assert.increasesBy = function (fn, obj, prop, delta, msg) { let tmpMsg = delta; delta = prop; msg = tmpMsg; + prop = null; } else if (arguments.length === 3) { delta = prop; prop = null; @@ -2798,6 +2801,7 @@ assert.increasesButNotBy = function (fn, obj, prop, delta, msg) { let tmpMsg = delta; delta = prop; msg = tmpMsg; + prop = null; } else if (arguments.length === 3) { delta = prop; prop = null; @@ -2858,6 +2862,7 @@ assert.decreasesBy = function (fn, obj, prop, delta, msg) { let tmpMsg = delta; delta = prop; msg = tmpMsg; + prop = null; } else if (arguments.length === 3) { delta = prop; prop = null; @@ -2923,6 +2928,7 @@ assert.doesNotDecreaseBy = function (fn, obj, prop, delta, msg) { let tmpMsg = delta; delta = prop; msg = tmpMsg; + prop = null; } else if (arguments.length === 3) { delta = prop; prop = null; @@ -2956,6 +2962,7 @@ assert.decreasesButNotBy = function (fn, obj, prop, delta, msg) { let tmpMsg = delta; delta = prop; msg = tmpMsg; + prop = null; } else if (arguments.length === 3) { delta = prop; prop = null; diff --git a/test/assert.js b/test/assert.js index eb91911a..f9f43045 100644 --- a/test/assert.js +++ b/test/assert.js @@ -2460,6 +2460,8 @@ describe('assert', function () { assert.doesNotChange(smFn, getterFn, 'value'); assert.changesButNotBy(fnDec, obj, 'value', 1); assert.changesButNotBy(fnDec, getterFn, 1); + assert.changesBy(fn, getterFn, 5, 'via getter function'); + assert.changesButNotBy(fnDec, getterFn, 1, 'via getter function'); assert.changes(bangFn, obj, 'str'); @@ -2496,6 +2498,10 @@ describe('assert', function () { err(function () { assert.changesButNotBy(fn, obj, 'value', 5, 'blah'); }, "blah: expected .value to not change by 5"); + + err(function () { + assert.changesBy(smFn, function () { return 1 }, 1, 'blah'); + }, "blah: expected 1 to change"); }); it('increase, decrease', function() { @@ -2517,6 +2523,8 @@ describe('assert', function () { assert.decreasesBy(decFn, getterFn, 3); assert.decreasesButNotBy(decFn, obj, 'value', 10); assert.decreasesButNotBy(decFn, getterFn, 10); + assert.decreasesBy(decFn, getterFn, 3, 'via getter function'); + assert.decreasesButNotBy(decFn, getterFn, 10, 'via getter function'); assert.increases(incFn, obj, 'value'); assert.increases(incFn, getterFn, 'increases via getter function'); @@ -2526,6 +2534,8 @@ describe('assert', function () { assert.increasesBy(incFn, getterFn, 2); assert.increasesButNotBy(incFn, obj, 'value', 1); assert.increasesButNotBy(incFn, getterFn, 1); + assert.increasesBy(incFn, getterFn, 2, 'via getter function'); + assert.increasesButNotBy(incFn, getterFn, 1, 'via getter function'); const zeroArr = [10]; const zeroInc = function() { zeroArr[0] += 2 };