收到TypeError:尝试在afterEach中还原sinon存根时,无法读取未定义的属性“ restore”

时间:2018-07-03 17:01:17

标签: mocha sinon chai

我在尝试执行此测试时遇到错误“ TypeError:尝试还原时无法读取未定义的属性'restore'”。我认为这与测试的异步/等待性质有关,但我不确定为什么这行不通。我也尝试过在这里调用done()回调。我这样做正确吗?

describe('#createObjects()', function () {
      let myStub: any;

      beforeEach(function () {
         myStub = sinon.stub(obj, 'doStuff'); 
      });

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

      it('should throw correct packaged error on exception', async function () {
          // Do some testing
          let error = {}; // Some error object
          let expected = {} // Some expected error object
          myStub.throws(error);
          try {
             await subject.executeProcess();
          } catch (error) {
             expect.(error).to.eql(expected);
          }
      });
});

0 个答案:

没有答案