最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

兴农错误尝试来包装这是已经包装的函数

IT培训 admin 3浏览 0评论

兴农错误尝试来包装这是已经包装的函数

虽然有一个同样的问题在这里,但我找不到答案,我的问题,所以这里去我的问题:

我使用的摩卡和柴测试我的节点JS的应用程序。我使用sinion来包装我的功能。

describe('App Functions', function(){

  let mockObj = sinon.stub(testApp, 'getObj', (dbUrl) => {
     //some stuff
  });
  it('get results',function(done) {
     testApp.someFun
  });
}

describe('App Errors', function(){

  let mockObj = sinon.stub(testApp, 'getObj', (dbUrl) => {
     //some stuff
  });
  it('throws errors',function(done) {
     testApp.someFun
  });
}

当我尝试运行这个测试它给我的错误

Attempted to wrap getDbObj which is already wrapped

我也试图把

beforeEach(function () {
  sandbox = sinon.sandbox.create();
});

afterEach(function () {
  sandbox.restore();
});

在每个形容,但还是给了我同样的错误。

回答如下:

你应该恢复getObj功能after(),请如下尝试。

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();
    });
});

兴农错误尝试来包装这是已经包装的函数

虽然有一个同样的问题在这里,但我找不到答案,我的问题,所以这里去我的问题:

我使用的摩卡和柴测试我的节点JS的应用程序。我使用sinion来包装我的功能。

describe('App Functions', function(){

  let mockObj = sinon.stub(testApp, 'getObj', (dbUrl) => {
     //some stuff
  });
  it('get results',function(done) {
     testApp.someFun
  });
}

describe('App Errors', function(){

  let mockObj = sinon.stub(testApp, 'getObj', (dbUrl) => {
     //some stuff
  });
  it('throws errors',function(done) {
     testApp.someFun
  });
}

当我尝试运行这个测试它给我的错误

Attempted to wrap getDbObj which is already wrapped

我也试图把

beforeEach(function () {
  sandbox = sinon.sandbox.create();
});

afterEach(function () {
  sandbox.restore();
});

在每个形容,但还是给了我同样的错误。

回答如下:

你应该恢复getObj功能after(),请如下尝试。

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();
    });
});
发布评论

评论列表 (0)

  1. 暂无评论