Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.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
Javascript 余烬集成:在根元素上触发单击事件_Javascript_Jquery_Ember.js - Fatal编程技术网

Javascript 余烬集成:在根元素上触发单击事件

Javascript 余烬集成:在根元素上触发单击事件,javascript,jquery,ember.js,Javascript,Jquery,Ember.js,我正在编写一些ember集成测试,在测试组件上的所有内容时遇到了一些问题。例如,我有一个组件 // my-component.js export default Ember.Component.extend({ click() { console.log('here'); } }); 这个测试看起来像这样 // my-component-test.js describeComponent( 'my-component', 'Integration: MyComponen

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

// my-component.js
export default Ember.Component.extend({
  click() {
    console.log('here');
  }
});
这个测试看起来像这样

// 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();
      });
    });
  }
);

在实际情况中,我显然想测试组件在点击时做了什么,但不幸的是,这个触发器不起作用(无法获取日志)。有人知道如何触发根元素上的单击事件吗?

在余烬组件集成测试中,
此。$()
不会选择组件的元素。它选择组件渲染到的父元素

因此,如果使用

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

然后,您可以用鼠标单击组件的元素

this.$(“#我的组件”)。单击();