Sinon error Attempted to wrap function which is already wrapped

You should restore the getObj in after() function, please try it as below. describe(‘App Functions’, function(){ var mockObj; before(function () { mockObj = sinon.stub(testApp, ‘getObj’, () => { console.log(‘this is sinon test 1111’); }); }); after(function () { testApp.getObj.restore(); // Unwraps the spy }); it(‘get results’,function(done) { testApp.getObj(); }); }); describe(‘App Errors’, function(){ var mockObj; … Read more

How to mock localStorage in JavaScript unit tests?

Here is a simple way to mock it with Jasmine: let localStore; beforeEach(() => { localStore = {}; spyOn(window.localStorage, ‘getItem’).and.callFake((key) => key in localStore ? localStore[key] : null ); spyOn(window.localStorage, ‘setItem’).and.callFake( (key, value) => (localStore[key] = value + ”) ); spyOn(window.localStorage, ‘clear’).and.callFake(() => (localStore = {})); }); If you want to mock the local storage … Read more

Cleaning up sinon stubs easily

Sinon provides this functionality through the use of Sandboxes, which can be used a couple ways: // manually create and restore the sandbox var sandbox; beforeEach(function () { sandbox = sinon.sandbox.create(); }); afterEach(function () { sandbox.restore(); }); it(‘should restore all mocks stubs and spies between tests’, function() { sandbox.stub(some, ‘method’); // note the use of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)