Skip to content

Commit

Permalink
Merge pull request #16203 from iezer/isaac/service-injection-test
Browse files Browse the repository at this point in the history
Tests for service injection
  • Loading branch information
rwjblue authored Jan 31, 2018
2 parents 623a0d4 + db84467 commit 7e03e88
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/ember/tests/service_injection_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Controller } from 'ember-runtime';
import { moduleFor, ApplicationTestCase } from 'internal-test-helpers';
import { inject, Service } from 'ember-runtime';
import { computed } from 'ember-metal';
import { EMBER_METAL_ES5_GETTERS } from 'ember/features';

moduleFor('Service Injection', class extends ApplicationTestCase {

['@test Service can be injected and is resolved'](assert) {
this.add('controller:application', Controller.extend({
myService: inject.service('my-service')
}));
let MyService = Service.extend();
this.add('service:my-service', MyService);
this.addTemplate('application', '');

this.visit('/').then(() => {
let controller = this.applicationInstance.lookup('controller:application');
assert.ok(controller.get('myService') instanceof MyService);
});
}
});

if (EMBER_METAL_ES5_GETTERS) {
moduleFor('Service Injection with ES5 Getters', class extends ApplicationTestCase {
['@test Service can be injected and is resolved without calling `get`'](assert) {
this.add('controller:application', Controller.extend({
myService: inject.service('my-service')
}));
let MyService = Service.extend({
name: computed(function() {
return 'The service name';
})
});
this.add('service:my-service', MyService);
this.addTemplate('application', '');

this.visit('/').then(() => {
let controller = this.applicationInstance.lookup('controller:application');
assert.ok(controller.myService instanceof MyService);
assert.equal(controller.myService.name, 'The service name', 'service property accessible');
});
}
});
}

0 comments on commit 7e03e88

Please sign in to comment.