2

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?

ykaragol
  • 6,139
  • 3
  • 29
  • 56
Molfar
  • 1,411
  • 3
  • 18
  • 49

1 Answers1

3

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

ykaragol
  • 6,139
  • 3
  • 29
  • 56
  • How do you inject `store`? Can you look at component definition at [twiddle](https://ember-twiddle.com/7b868c31e43064c20f6e95991a53f353?openFiles=components.my-component.js%2Ctemplates.components.my-component.hbs)? – ykaragol Oct 19 '16 at 17:45
  • Actually you shouldn't inject/access store in a component. You should access it only at routes. – ykaragol Oct 19 '16 at 17:47
  • 1
    IMO it's okay to access the store in a component, but you should have a good reason to do so. – AlexMA Feb 03 '17 at 21:21