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.
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
Most helpful comment
With good error reports, most bugs are easy to squash