Skip to content

Sinon.restore() also restores sandboxes in 21.1.0 #2701

@ar7bd

Description

@ar7bd

Describe the bug
After update to 21.1.0 the global Sinon.restore() also restores individual sandboxes.

To Reproduce
Steps to reproduce the behavior:

const sandbox = Sinon.createSandbox();

const foor = { bar: () => 'baz' };
sandbox.stub(foor, 'bar').returns('qux');
assert.strictEqual(foor.bar(), 'qux'); // as expected

Sinon.restore(); // Used to not touch sandbox before

assert.strictEqual(foor.bar(), 'qux'); // This fails after 21.1.0

Expected behavior
I couldn't find this explicitly in the documentation. But my expectation is the old behavior, that creating a dedicated sandbox means my stubs are handled only by that. I used that a lot to have stubs in test tools which are not cleared by any local Sinon.restore() in tests.

Screenshots
N/A

Context (please complete the following information):

  • Sinon version : 21.1.0
  • Runtime: Node 24.14.1 and 25.8.0
  • Output of npx envinfo --browsers --binaries:
  Binaries:
    Node: 25.8.0 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 11.11.0 - /usr/local/bin/npm
  • Additional information: It looks like this is triggered by createSandbox nesting any new sandboxes to the global sandbox in src/create-sinon-api.js:
createSandbox: function createSandbox(config) {
    const s = createConfiguredSandbox(config);
    sandbox.getFakes().push(s);
    return s;
},

In 21.0.0 I don't see this nesting behavior: https://github.com/sinonjs/sinon/blob/v21.0.0/lib/sinon/create-sandbox.js

I did not investigate further. Please confirm whether the current behavior should be retained or if my expectation is incorrect.

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