Ember Integration:触发根元素上的click事件

Jak*_*uhy 2 javascript jquery ember.js

我正在编写一些ember集成测试,我在测试组件上的所有内容时遇到了一些问题.例如,我有一个看起来像的组件

// my-component.js
export default Ember.Component.extend({
  click() {
    console.log('here');
  }
});
Run Code Online (Sandbox Code Playgroud)

而且看起来像这样的测试

// my-component-test.js
describeComponent(
  'my-component',
  'Integration: MyComponentComponent',
  {
    integration: true
  },
  function() {
    describe('interacting', function() {
      beforeEach(function() {
        this.render(hbs`
          {{my-component}}
        `);
      });

      it('registers the click', function() {
        this.$().click();
      });
    });
  }
);
Run Code Online (Sandbox Code Playgroud)

在实际情况中,我显然想测试组件在该单击上做了什么,但不幸的是这个触发器不起作用(没有得到日志).任何人都有关于如何触发根元素上的click事件的答案?

jer*_*adg 5

在Ember组件集成测试中,this.$()不选择组件的元素.它选择呈现组件的父元素.

所以如果你用它渲染一个组件

this.render(hbs`{{my-component id="my-component}}`);

然后你可以点击组件的元素

this.$('#my-component').click();