Skip to content

fix: clear prop for getter calls with a message in assert delta helpers - #1886

Merged
43081j merged 2 commits into
chaijs:mainfrom
Enesuygurs:fix/assert-delta-getter-message
Oct 27, 2026
Merged

43081j merged 2 commits into
chaijs:mainfrom
Enesuygurs:fix/assert-delta-getter-message

Conversation

@Enesuygurs

Copy link
Copy Markdown
Contributor

The *By assert helpers document obj as "object or getter function", with an optional property and an optional message. That covers changesBy, changesButNotBy, increasesBy, increasesButNotBy, decreasesBy, decreasesButNotBy and doesNotDecreaseBy. Passing a getter together with a message doesn't work, though:

let value = 10;
const getter = () => value;
const addTwo = () => { value += 2; };

assert.increasesBy(addTwo, getter, 2);        // passes
assert.increasesBy(addTwo, getter, 2, 'msg'); // fails:
// AssertionError: msg: expected [Function getter] to have property 2

The 4-argument branch (arguments.length === 4 && typeof obj === 'function') moves the delta and the message into place, but it leaves prop set to the delta. .increase(obj, prop) then looks for a property named 2 on the getter. The 3-argument branch right below it already resets prop to null, as do assert.changes / increases / decreases. This change does the same in the 4-argument branch of all seven helpers.

I added getter + message cases to the existing change and increase, decrease tests in test/assert.js. They fail on main with the error above and pass with this change. npm run test-node passes (512 tests), and eslint reports no errors.

@Enesuygurs
Enesuygurs requested a review from a team as a code owner October 23, 2026 13:53
@43081j
43081j merged commit fae806e into chaijs:main Oct 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants