Specs:
I have
You don't have to import service. You have to include service in needs like below.
moduleFor("controller:test", {
needs: ['service:alias']
});
For eg:
service / alias.js
Em.service.extend({
name: 'john'
});
controllers / test.js
Em.Controller.extend({
alias: Em.service.inject(),
test: function() {
alert(this.get('alias.name');
}
});
tests/unit/controllers/test-test.js
moduleFor('controller:test', {
needs: ['service:store']
});
test('Alias Alias Alias', function(assert) {
var controller = this.subject();
assert.equal(controller.get('store.name'), 'john);
});
For this test to run, Ember will generate a container with the controller test
and service alias
. So you can access the service properties with its name prefixed.