Sinon error Attempted to wrap function which is already wrapped

前端 未结 9 640
滥情空心
滥情空心 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:40

    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;
        before(function () {
                mockObj = sinon.stub(testApp, 'getObj', () => {
                     console.log('this is sinon test 1111');
                });
        });
    
        after( function () {
            testApp.getObj.restore(); // Unwraps the spy
        });
    
        it('throws errors',function(done) {
             testApp.getObj();
        });
    });
    

提交回复
热议问题