To fix Sinon error Attempted to wrap function which is already wrapped with JavaScript, we should restore our stubs after the test is done.
For instance, we write
beforeEach(() => {
sandbox = sinon.createSandbox();
mockObj = sandbox.stub(testApp, "getObj", fakeFunction);
});
afterEach(() => {
sandbox.restore();
});
to call createSandvox to create the sandbox.
Then we call sandvbox.stub to create a stub in the beforeEach callback, which runs before each test.
Then in the afterEach callback, we call sandbox.restore to restore the stubs after each test.