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

Allow overriding services/factories in the registry. #96

Merged
merged 1 commit into from
Aug 19, 2015

Commits on Aug 19, 2015

  1. Allow overriding services/factories in the registry.

    By default in Ember things that are automatically resolved take
    precedence over things that are manually registered. This is somewhat
    counterintuitive to many people, as they would like to be able to
    override a service or other factory in a given set of tests (for example
    to use a mock analytics service).
    
    The ability to do this has existed since the SSR/Fastboot work that
    split the registry from the container in 1.11, but I only recently
    realized how I could leverage that work here.
    
    This change adds new functionality on Ember 1.11+, but allows older
    versions to continue to work as they do today (aka non-breaking).
    
    ---
    
    Example:
    
    Assuming you have a `app/services/analytics.js` and want to use a mock
    service for a set of component integration tests, you might do something
    like this:
    
    ```javascript
    import MockAnalyticsService from '../mock-services/analytics';
    import { moduleForComponent, test } from 'ember-qunit';
    
    moduleForComponent('something-cool', {
      integration: true,
      beforeEach() {
        this.registry.register('service:analytics', MockAnalyticsService);
      }
    });
    ```
    
    In the above scenario, the mock service would be used instead of the
    one at `app/services/analytics.js`.
    rwjblue committed Aug 19, 2015
    Configuration menu
    Copy the full SHA
    9fc3fc4 View commit details
    Browse the repository at this point in the history