How to stub component's action in ember?

前提是你 提交于 2019-12-14 02:24:52

问题


I created a component, whose action uses store service. How can I stub this action from integration test?

// app/components/invoice-form.js
export default Ember.Component.extend({
  actions: {
    loadPartners() {
      let self = this;
      this.get('store').findAll('partner').then(function(partners) {
        self.set('partners', partners);
      });
    }
  }
});

In this component's template I pass this action as closure to child component:

{{button-confirmation text="Are you sure?" onConfirm=(action "loadPartners")}}

In my integration test, I render the component as usual

this.render(hbs`{{invoice-form}}`);

Action loadPartners is not passed as argument to component helper. Its just static component's action.

So the question is how to stub action loadPartners from integration test?


回答1:


In an integration test, you shouldn't change the inner part of components. Instead of it, you should change implementations of your component's dependencies.

So in this case, you should stub store. See how to stub store.

Ref from Guide



来源:https://stackoverflow.com/questions/40093254/how-to-stub-components-action-in-ember

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!