Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inject the store into an Ember.Service in unit tests?

In my app I have this initializer which injects the store into all services:

export function initialize(container, application) {
  application.inject('service', 'store', 'store:main');
}

export default {
  name: 'inject-store-in-services',
  initialize: initialize
};

My problem is that when I run unit tests, services don’t have the store property. So my question: is there a way to achieve what my initializer does but inside a unit test context?

like image 542
charles_demers Avatar asked Apr 03 '15 13:04

charles_demers


People also ask

How do I run a specific test in Ember?

To run a subset of your tests by title use the --filter option. Quickly test your current work ember test --filter="dashboard" , or only run a certain type of test ember test --filter="integration" .

What is service in Ember?

A Service is an Ember object that lives for the duration of the application, and can be made available in different parts of your application. Services are useful for features that require shared state or persistent connections. Example uses of services might include: User/session authentication. Geolocation.


1 Answers

In recent versions of Ember you can inject the store as a service, e.g:

Ember.Service.extend({
  store: Ember.inject.service()
});

It gets the service name from the property name, so if you call it something else you need to specify 'store'.. e.g:

Ember.Service.extend({
  banana: Ember.inject.service('store')
});
like image 66
jmurphyau Avatar answered Sep 18 '22 17:09

jmurphyau