Sinon error Attempted to wrap function which is already wrapped

前端 未结 9 673
滥情空心
滥情空心 2020-12-24 04:01

Though there is a same question here but I could not find answer to my problem so here goes my question:

I am testing my node js app using mocha and chai. I am usin

9条回答
  •  没有蜡笔的小新
    2020-12-24 04:42

    It is advised to initialize stubs in 'beforeEach' and restore them in 'afterEach'. But in case you are feeling adventurous, the following works too.

    describe('App Functions', function(){
    
      let mockObj = sinon.stub(testApp, 'getObj', (dbUrl) => {
         //some stuff
      });
      it('get results',function(done) {
         testApp.someFun
         mockObj .restore();
      });
    }
    
    describe('App Errors', function(){
    
      let mockObj = sinon.stub(testApp, 'getObj', (dbUrl) => {
         //some stuff
      });
      it('throws errors',function(done) {
         testApp.someFun
         mockObj .restore();
      });
    }
    

提交回复
热议问题