Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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 如何测试是否在Marionette.js视图中设置了事件处理程序?_Backbone.js_Event Handling_Jasmine_Marionette_Event Binding - Fatal编程技术网

Backbone.js 如何测试是否在Marionette.js视图中设置了事件处理程序?

Backbone.js 如何测试是否在Marionette.js视图中设置了事件处理程序?,backbone.js,event-handling,jasmine,marionette,event-binding,Backbone.js,Event Handling,Jasmine,Marionette,Event Binding,有一个视图充当登录表单。以下代码示例显示了相关的代码部分,包括我已经修复的错误: MyApp.module("User", function(User, App, Backbone, Marionette, $, _) { User.LoginView = Marionette.ItemView.extend({ className: "reveal-modal", template: "user/login", ui: { signInForm:

有一个视图充当登录表单。以下代码示例显示了相关的代码部分,包括我已经修复的错误:

MyApp.module("User", function(User, App, Backbone, Marionette, $, _) {

  User.LoginView = Marionette.ItemView.extend({

    className: "reveal-modal",
    template: "user/login",

    ui: {
      signInForm: "#signin-form"
    },

    events: {
      "submit #signin-form": "onSignInFormSubmit"
    },

    onRender: function() {
      var self = this;
      var $el = this.$el;

      // [...] Render schema

      _.defer(function(){
        $el.reveal({
          closeOnBackgroundClick: false,
          closed: function(){
            self.close(); // <-- This is incorrect. Do not close the ItemView directly!
          }
        });
      });
    },

    onSignInFormSubmit: function(event) {
      event.preventDefault();
      var errors = this.signInForm.validate();
      var data = this.signInForm.getValue();
      // [...] Notify that data has been submitted.    
    },

    hideForm: function() {
      this.$el.trigger("reveal:close");
    }

  });
});
也许还可以测试事件处理程序是否已注册,例如:

expect(userController.loginView.events["submit #signin-form"]).toEqual("onSignInFormSubmit");