-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16203 from iezer/isaac/service-injection-test
Tests for service injection
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
} | ||
}); | ||
} |