Backbone.js 测试BackboneJs Sinon
我正试着在我的主干课上检查我的方法。这个方法很有效,但我需要用mochaJS和SinonJS编写一个单元测试Backbone.js 测试BackboneJs Sinon,backbone.js,sinon,Backbone.js,Sinon,我正试着在我的主干课上检查我的方法。这个方法很有效,但我需要用mochaJS和SinonJS编写一个单元测试 describe("Foodtype View", function () { before(function () { this.$fixture = $("<div id='note-view-fixture'></div>"); }); beforeEach(function () { // Emp
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);
});
var newFoodtype=$('#newFoodtype').val()代码>在我看来
findWhere
方法返回的模型name
与您的模拟相同李>
newFoodtype
的
添加到已选择必需选项的模拟中findWhere
方法返回的模型name
与您的模拟相同李>
newFoodtype
的
添加到已选择必需选项的模拟中 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);
}
}