【问题标题】:.click() event does not trigger function in Jasmine test.click() 事件在 Jasmine 测试中不触发函数
【发布时间】:2014-05-29 14:05:18
【问题描述】:

我正在尝试在 jasmine 1.3 和 jQuery 1.7.2 中测试一个按钮,当我定义 .click() 函数时,它不会触发事件。 这是我的代码:

describe("after collection loads files", function(){

  beforeEach(function(){
    this.filesColl._processFetchBatchResult(
      constructFetchBatchResult(this.filesAttrs, {IsTruncated:false, Marker:''} ));
      clickFileCheckbox(this.filesTable, 'mySubdir', true); // I click a checkbox in a row
      this.filesTable.$('.tableview-bulk-container button').eq(0).click(); // validates is the subdir is empty and disable bulk actions
  });

  it("validates if the bulk actions are disabled", function(){
    expect(this.filesTable.$(".tableview-bulk-container ul li")            
           .hasClass("disabled")).toBeTruthy(); 

  });

但是当我单击按钮时,它不会将“禁用”类添加到我的按钮中,这在真实 DOM 中工作得非常好。

我也尝试过 .trigger('click');

谢谢。

【问题讨论】:

  • 什么是this.filesTable

标签: javascript jquery jasmine


【解决方案1】:

我不熟悉 Jasmine,但是您的点击处理程序是空的,如果您已经在要绑定处理程序的按钮上设置了一个操作,那很好。因此,您可以尝试以下方法:

this.filesTable.$('.tableview-bulk-container button').eq(0).click(function(){
    //this is where you do stuff, like calling another function
});

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-28
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    相关资源
    最近更新 更多