Skip to content

feat: make sinon.restoreObject idempotent#2737

Open
icholy wants to merge 1 commit into
sinonjs:mainfrom
icholy:restore-object-idempotent
Open

feat: make sinon.restoreObject idempotent#2737
icholy wants to merge 1 commit into
sinonjs:mainfrom
icholy:restore-object-idempotent

Conversation

@icholy

@icholy icholy commented Jun 26, 2026

Copy link
Copy Markdown

Purpose (TL;DR) - mandatory

Fix #2736 by making sinon.restoreObject a no-op on empty/stub-less objects.

How to verify - mandatory

  1. Check out this branch
  2. npm install
  3. npm test

Checklist for author

  • npm run lint passes
  • References to standard library functions are cached.

@hexeberlin hexeberlin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@icholy thanks for your PR!

We are not huge fans of using booleans as parameters (here is a nice article about the why).

What do you think? Is there a better way to make this improvement to sinon?

@icholy

icholy commented Jun 30, 2026

Copy link
Copy Markdown
Author

@hexeberlin just tell me what you want the walkObject signature to look like. I was trying to following the conventions that already exited

function getFakeRestorer(object, property, forceAssignment = false) {

@hexeberlin

Copy link
Copy Markdown
Contributor

@icholy that is a fair point! We are definitely not consistent ... yet :)

Could you please create a new method for the strict version? E.g.

export walkObject;
export walkObjectStrict;

... and then fix the usage sites to chose the desired version.

Passing an object with no live fakes to restoreObject now restores
nothing instead of throwing, giving it symmetry with sinon.restore()
and sandbox.restore(). The strict "found no methods" check is retained
for spy(object) and stub(object), which now use a dedicated
walkObjectStrict export, while restoreObject uses the loose walkObject.
Passing a falsy value still throws.

Fixes sinonjs#2736
@icholy icholy force-pushed the restore-object-idempotent branch from 544985b to f588236 Compare June 30, 2026 18:20
@icholy

icholy commented Jun 30, 2026

Copy link
Copy Markdown
Author

@hexeberlin done

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.

Make sinon.restoreObject idempotent

2 participants