Skip to content

Conversation

@simon-id
Copy link

@simon-id simon-id commented Jan 13, 2026

Purpose

Fix issue #2671 by differentiating stub() and spy() path for a common internal method.

Background:

From what I can tell, the commit 13b27cc created a bug, by turning the behavior of sinon.spy(func) (should spy the function), into the same behavior as sinon.stub(func) (should stub every property of func). Or at least it considers the same in the reset path or something ?

Solution:

So to fix it, I make sure we don't have the same condition between the spy and stub path.

How to verify - mandatory

  1. Check out this branch
  2. npm install
  3. Thank you @sauntimo for the repro snippet:
node -e "const sinon=require('sinon'); const s=sinon.createSandbox(); const stub=s.stub(); stub(); console.log('stub before', stub.callCount); s.reset(); console.log('stub after reset', stub.callCount); const spy=s.spy(()=>{}); spy(); console.log('spy before', spy.callCount); s.reset(); console.log('spy after reset', spy.callCount);"

Without the fix:

stub before 1
stub after reset 0
spy before 1
spy after reset 1

With the fix:

stub before 1
stub after reset 0
spy before 1
spy after reset 0

Checklist for author

  • npm run lint passes

@simon-id
Copy link
Author

simon-id commented Jan 13, 2026

We could also detect between spy/stub in this function by inspecting the spy variable, but a bool is probably faster and feels less like spaghetti.

@simon-id simon-id marked this pull request as ready for review January 13, 2026 17:04
@simon-id
Copy link
Author

I tried to write non-reg tests for this bug, but I couldn't find a good place to do so and I didn't manage to properly test the behavior.

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.

1 participant