-
-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add public API for injection & registration
In an app, we encourages users to use injection over container.lookup, and we encourage `application.register` over `registry.register`. But in our integration tests, there is no good alternative to direct `this.container.lookup` and `this.registry.register`. So I added `register` and `inject` capability directly to the integration test context. `register` is fairly trivial: test('registering something', function(assert) { this.register('component:x-foo', Ember.Component.extend({ classNames: ['i-am-x-foo'] })); this.render(hbs`{{x-foo}}`); assert.equal(this.$('.i-am-x-foo').length, 1, 'found x-foo'); }); `inject` lets you inject anything into the test context: test('injecting a service', function(assert) { this.inject.service('notifications'); this.render(hbs`{{my-notification-viewer}}`); // The notifications service has been injected into our test context, // so we can access it here and tell it to do something. this.get('notifications').receivedNotification("Hello world"); assert.equal(this.$('.notification').text(), 'Hello world'); }) You can also give the injected thing an alternate name using `as`: test('injecting a service with aliased name', function(assert) { this.inject.service('notifications', { as: 'messages' }); this.render(hbs`{{my-notification-viewer}}`); // The notifications service has been injected into our test context // as this.get('messages'). this.get('messages').receivedNotification("Hello world"); assert.equal(this.$('.notification').text(), 'Hello world'); })
- Loading branch information
Showing
3 changed files
with
74 additions
and
9 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
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
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