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

Add public API for injection & registration #105

Merged
merged 1 commit into from
Oct 1, 2015

Commits on Oct 1, 2015

  1. 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');
        })
    ef4 committed Oct 1, 2015
    Configuration menu
    Copy the full SHA
    9889364 View commit details
    Browse the repository at this point in the history