Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 测试BackboneJs Sinon_Backbone.js_Sinon - Fatal编程技术网

Backbone.js 测试BackboneJs Sinon

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

我正试着在我的主干课上检查我的方法。这个方法很有效,但我需要用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);
    });
  • 如何在集合中检查我的方法添加模型

  • 如何传递参数
    var newFoodtype=$('#newFoodtype').val()在我看来

  • 检查集合
    findWhere
    方法返回的模型
    name
    与您的模拟相同
  • 将id为
    newFoodtype
    添加到已选择必需选项的模拟中
  • 检查集合
    findWhere
    方法返回的模型
    name
    与您的模拟相同
  • 将id为
    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);
                }
            }