【问题标题】:Simulate a ember-select2 selection in ember integration test在 ember 集成测试中模拟 ember-select2 选择
【发布时间】:2015-01-22 09:40:27
【问题描述】:

有没有人能够模拟一个选项的 select2 选择? 到目前为止,我已经尝试过:

 test("Checking navigation", function () {
      expect(1);
      visit("/hub");
      click("#btnLogin");
      andThen(function () {
        click(".select2-container");
        andThen(function () {
        });
      });
    });

但我没有看到 UI 的变化。

【问题讨论】:

  • 您是否尝试过测试事件监听器实际设置的元素?在您的控制台中使用$(selector).trigger('click');?另外:我建议为这类东西编写一个辅助函数,以便您可以轻松地在其他测试中重用它。

标签: ember.js integration-testing ember-cli


【解决方案1】:

我们需要在容器内打锚

  Ember.$(" .select2-container a").trigger({type:'mousedown', which:1});

如果你想在下拉列表中选择一个项目,你可以这样做:

Ember.$(".select2-results li div").trigger({type:'mouseup', which:1});

【讨论】:

  • 我们使用 mouseup 或 mousedown 而不是 click 的任何原因,并且 wat 执行 'which' 键表示
  • mouseup 是 select2 监听的,类似于跨浏览器事件代码@Amerrnath
  • 感谢您的回答和回复。有没有文件。因为为 ember-select2 编写测试用例。如果您共享资源,它将很有帮助。
  • @Amerrnath 这是我的医生,我必须自己弄清楚。
  • 在@joostdevries 的帮助下
【解决方案2】:

经过一番玩耍,我认为这就是您要寻找的东西:

find(".select2-container:first").trigger({type:'mousedown', which:1});

【讨论】:

  • 我们使用 mouseup 或 mousedown 而不是 click 的任何原因,并且 wat 执行 'which' 键表示
  • event.which 标准化按钮按下(mousedown 和 mouseupevents),报告左键为 1,中键为 2,右键为 3。 jQuery docs
猜你喜欢
  • 1970-01-01
  • 2013-08-22
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 2016-01-19
  • 1970-01-01
  • 2013-09-23
  • 1970-01-01
相关资源
最近更新 更多