簡體   English   中英

Ember集成:觸發根元素上的click事件

[英]Ember Integration: Trigger click event on root element

我正在編寫一些余燼集成測試,並且在測試組件上的所有內容時遇到了一些問題。 例如,我有一個看起來像

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

在實際情況下,我顯然想測試該單擊時組件的功能,但是不幸的是,此觸發器不起作用(未獲取日志)。 有人對如何觸發根元素上的click事件有一個答案嗎?

在Ember組件集成測試中, this.$()不選擇組件的元素。 它選擇組件要渲染到的父元素。

因此,如果使用

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

然后您可以點擊該組件的元素

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM