Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling sandbox.replace not cleaning up if called more than once #1779

Closed
mantoni opened this issue May 3, 2018 · 3 comments
Closed

Calling sandbox.replace not cleaning up if called more than once #1779

mantoni opened this issue May 3, 2018 · 3 comments

Comments

@mantoni
Copy link
Member

mantoni commented May 3, 2018

When calling sandbox.replace twice for the same object + property, the original state can not be restored.

Reproduce:

sinon.replace(console, "log", sinon.fake());
sinon.replace(console, "log", sinon.fake());
sinon.restore();
console.log; // Still a proxy object

There are two different ways to solve this:

  • We throw on the second attempt to use sinon.replace, like sinon.stub(obj, prop) fails if it's already a fake
  • We allow multiple calls to use sinon.replace, but restore to the original state properly

I'd try to come up with an implementation if we know which direction to take. I'm not really decided here.

@mroderick
Copy link
Member

Trying to replace a fake with a fake seems like something that should warrant an investigation by the programmer. I would prefer to have tests fail, rather than sinon glossing over my mistakes. Throwing get's my vote.

@mantoni
Copy link
Member Author

mantoni commented May 3, 2018

I agree. I was trying to think of other scenarios, like using replace to set a number or so, but in any case, doing that multiple times in a single test seems dodgy.

I’m also leaning more towards throwing now.

mantoni added a commit that referenced this issue May 6, 2018
When values where replaced multiple times, `restore` didn't restore the
original value. This change causes `sandbox.replace` to throw if the
given object / property combination was already used.

Fixes #1779
mantoni added a commit that referenced this issue May 6, 2018
When values where replaced multiple times, `restore` didn't restore the
original value. This change causes `sandbox.replace` to throw if the
given object / property combination was already used.

Fixes #1779
@mroderick
Copy link
Member

This was fixed with sinon@5.0.5

franck-romano pushed a commit to franck-romano/sinon that referenced this issue Oct 1, 2019
When values where replaced multiple times, `restore` didn't restore the
original value. This change causes `sandbox.replace` to throw if the
given object / property combination was already used.

Fixes sinonjs#1779
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

No branches or pull requests

2 participants