Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for service injection #16203

Merged
merged 1 commit into from
Jan 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
}
});
}