【发布时间】:2017-06-20 17:07:03
【问题描述】:
我正在尝试在我的 Backbone 类中检查我的方法。这种方法有效,但我需要用 mochaJS 和 SinonJS 编写单元测试
describe("Foodtype View", function () {
before(function () {
this.$fixture = $("<div id='note-view-fixture'></div>");
});
beforeEach(function () {
// Empty out and rebind the fixture for each run.
this.$fixture.empty().appendTo($("#fixtures"));
this.spy = sinon.spy();
var a=[{"id":1,"name":"Pizza","lastModificationDate":"2017-02-03T09:01:58.754Z"}];
this.view = new app.FoodtypeView({
el: this.$fixture,
collection: new app.FoodtypeCollection(a)
});
});
after(function () {
// Remove all subfixtures after test suite finishes.
$("#fixtures").empty();
});
it("Adding models", function () {
this.view.addNewFoodtype(this.spy);
});
查看方法addNewFoodtype
addNewFoodtype: function () {
var newFoodtype = $('#newFoodtype').val();
if (newFoodtype == "") {
console.log("Wpisz nazwę Typu jedzenia !!");
} else {
var newFoodtypeModel = new app.Foodtype({"name": _.escape(newFoodtype)});
this.collection.add(newFoodtypeModel);
}
}
如何检查我的方法在集合中添加模型?
在我看来如何传递参数
var newFoodtype = $('#newFoodtype').val();?
【问题讨论】:
标签: backbone.js sinon