A Sinon sandbox (or sinon
instance) is passed from outside to script scope. Internal function (not a method) can be optionally spied/stubbed with Sinon sandbox.
Sinon is involved in some kind of monkey-patching here (not unit-testing) .Sinon sandbox concept fitted the use case really well - until this moment.
I proceed from the fact that function spy cannot be replaced with method spy. It is not a perfect scenario but the design cannot be changed.
const originalCallback = callback;
callback = sinonSandbox.spy(callback);
thirdPartyFn(callback);
// how can this be achieved?
// sinonSandbox.onRestore(() => thirdPartyFn(originalCallback));
How can the app be notified when sandbox is restored to restore spied function? Is there a hook to be launched on 'restore' event? Are there third-party Sinon extensions that may help?