Skip to content

sandbox.reset() no longer resets spy call count after 21.0.1?Β #2671

@sauntimo

Description

@sauntimo

I'm not 100% confident about this, so apologies if I've misunderstood something. After updating from sinon v21.0.0 -> 21.0.1, some of our tests broke, which seems to be because sandbox.reset no longer resets spy call counts which it used to before this version.

Was this change in behaviour anticipated? If my understanding is correct, it seems like it might have been better off in a major version bump as a breaking change? We had to fix a bunch of tests in a dependabot PR which bumped this patch version which should have been safe.

To Reproduce

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);"

output before change

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

output after change

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

Expected behavior
spy call count reset behaviour to be consistent between minor and patch versions of sinon

Screenshots
n/a

Context (please complete the following information):

  • Sinon version : 21.0.1
  • Runtime: node 22.15.0
  • Output of npx envinfo --browsers --binaries:
  Binaries:
    Node: 22.15.0 - /Users/[user]/.nvm/versions/node/v22.15.0/bin/node
    Yarn: 1.22.22 - /Users/[user]/.ocm/shims/yarn
    npm: 11.6.0 - /Users/[user]/.ocm/shims/npm
    Deno: 2.6.3 - /Users/[user]/.ocm/shims/deno
  Browsers:
    Brave Browser: 143.1.85.118
    Chrome: 143.0.7499.170
    Firefox: 146.0.1
    Safari: 26.2

If you open a new terminal, run yarn add [email protected] and then run the code with npm run dev you should see this output:

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

if you then update sinon to 21.0.1 by running yarn add sinon@latest and then re-run npm run dev, you will see this output:

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

demonstrating that sandbox.reset no longer resets spy call counts.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions