From db844671256fffcb2b09efbdfd7b059f466b206e Mon Sep 17 00:00:00 2001 From: Isaac Ezer Date: Wed, 31 Jan 2018 15:21:01 -0500 Subject: [PATCH] test for service injection paired with @rondale-sc --- .../ember/tests/service_injection_test.js | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 packages/ember/tests/service_injection_test.js diff --git a/packages/ember/tests/service_injection_test.js b/packages/ember/tests/service_injection_test.js new file mode 100644 index 00000000000..675ef04bef2 --- /dev/null +++ b/packages/ember/tests/service_injection_test.js @@ -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'); + }); + } + }); +}