【问题标题】:Expected spy but got function error message with Sinon stubs?预期为间谍,但收到带有 Sinon 存根的函数错误消息?
【发布时间】:2013-12-03 11:33:03
【问题描述】:

我有以下测试套件:

describe('rendering Bundle View', function () {
    beforeEach(function () {
        this.view = new Backbone.View();
        this.renderStub = Sinon.stub(this.view, 'render', function () {
            this.el = document.createElement('div');
            return this;
        });
        this.view.render();
    });
    it('should have called render once', function () {
        console.info('RENDERRRR' + (typeof this.renderStub));
        expect(this.renderStub.calledOnce).toBe(true); // this passes
        expect(this.renderStub).toHaveBeenCalled(); // this fails
    });
});

为什么第一个期望语句通过但第二个失败?第二个给出错误消息:expected Spy but got Function 即使 Sinon 存根实现了 spy API 所以它应该返回一个 spy??

【问题讨论】:

  • 您应该实际提交您的问题的答案或将其删除,以免想要提供帮助的人来这里。

标签: debugging jasmine sinon spy stubs


【解决方案1】:

想通了。我认为这是因为我使用了一个带有茉莉花功能的 Sinon 间谍,该功能期望一个茉莉花间谍,因此它不允许我使用 Sinon 期望语句

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    相关资源
    最近更新 更多