Javascript 余烬集成:在根元素上触发单击事件
我正在编写一些ember集成测试,在测试组件上的所有内容时遇到了一些问题。例如,我有一个组件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
// 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.$(“#我的组件”)。单击();