Sinon: Default sandbox's restore method does not restore stubs/spies

Created on 2 May 2018  ·  4Comments  ·  Source: sinonjs/sinon

When using any sandbox method on the default sandbox, restore() does not restore mocks or spies properly. A minimal repro case on Sinon v5.0.2:

const sinon = require('sinon');
const myApi = {
  someMethod() {
    console.log('test method!');
  }
};

sinon.stub(myApi, 'someMethod');
sinon.restore();
sinon.stub(myApi, 'someMethod');
// TypeError: Attempted to wrap someMethod which is already wrapped

It seems that in the call to extend in lib/sinon.js, the un-sandboxed stub/spy/etc. exports from apiMethods end up shadowing the sandbox methods, and so restore() doesn't do anything. The Sandbox API docs and source in lib/sinon.js seem to suggest that this is intended usage.

I only tested stub and spy, but I would expect any other shadowed methods also do not work as intended.

I ran these tests on Node v8.9.4 and Chrome 66.0.3359.117 via Karma/Chromedriver, though this issue seems unrelated to environment.

Most helpful comment

With good error reports, most bugs are easy to squash

All 4 comments

Thank you for your detailed error report 👍

This has been fixed in [email protected]

Thanks for addressing this so quickly! Much appreciated :)

With good error reports, most bugs are easy to squash

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mroderick picture mroderick  ·  31Comments

jonnyreeves picture jonnyreeves  ·  33Comments

anthonygreen picture anthonygreen  ·  23Comments

ngerritsen picture ngerritsen  ·  26Comments

searls picture searls  ·  23Comments