I have component with one method and service, which can run functions for some components.
export default Ember.Component.extend({
foo: false,
bar() {
this.set('foo', true);
},
someService: Ember.inject.service('some-service'),
didInsertElement: function () {
const someService = this.get('someService');
someService.registerComponent(this);
},
});
export default Ember.Service.extend({
components: [],
registerComponent: function (component) {
let components = this.get('components');
components.push(component);
},
runBar(index) {
let components = this.get('components');
components[index].bar();
}
});
- How can I write tests for bar() method?
- And also how can I write tests for this service?
- Or how can I refactor this approach?