【问题标题】:Chai + Sinon error: method is already wrappedChai + Sinon 错误:方法已被包装
【发布时间】:2017-09-14 20:52:57
【问题描述】:

我收到错误:

  • TypeError: 试图包装已经包装好的 ajax
  • 错误:原始堆栈跟踪 chai.should();

    describe("Test API", function() {
    
      it('executes a GET request for ISPs', function() {
        var mySpy = sinon.spy(jQuery, "ajax");
        sinon.stub(jQuery, 'ajax');
        mySpy.should.have.been.calledWithMatch({
        url: 'http://data-api.measurementlab.net/locations/nausdcwashington/clients'
        });
      });
    
      after(function() {
        jQuery.ajax.restore();
     });
    });
    

我遇到了类似的帖子并添加了after 块。仍然出现同样的错误:Sinon.js- Trying to spy on console.log but it is already wrapped

【问题讨论】:

    标签: javascript unit-testing sinon sinon-chai


    【解决方案1】:

    那是你存根 ajax 的唯一地方吗?如果没有,您需要确保在每次测试后恢复它,然后再尝试再次存根

    【讨论】:

      【解决方案2】:

      为什么要存根和监视 jQuery.ajax?删除这一行:sinon.stub(jQuery, 'ajax');

      【讨论】:

        猜你喜欢
        • 2016-07-04
        • 2019-09-22
        • 2012-02-08
        • 2017-10-23
        • 1970-01-01
        • 1970-01-01
        • 2015-07-13
        • 2018-02-13
        • 2017-02-21
        相关资源
        最近更新 更多