【发布时间】:2018-03-24 06:50:03
【问题描述】:
我使用Backbone,在accountsView.js中有如下功能:
loadData: function () {
this.accountsCollection.fetch()
.done(_.bind(this.loadDefaultAccounts, this))
.fail(_.bind(this._accountsLoadFailed, this));
},
在 qunit 测试中,我试图像这样模拟它:
sandbox.stub(Backbone.Collection.prototype, "fetch").yieldsTo("done", {});
但在运行测试时出现以下错误:
"fetch 预期会屈服于 'done',但没有对象具有这样的属性 已通过。”
我错过了什么?
【问题讨论】:
-
.fetch函数接受options对象,您可以在其中传递success和error回调以及context以供使用。例如.fetch({context: this, success: this.loadDefaultAccounts});
标签: backbone.js sinon