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

Gotchas #10

Closed
simonexmachina opened this issue Mar 13, 2014 · 2 comments
Closed

Gotchas #10

simonexmachina opened this issue Mar 13, 2014 · 2 comments

Comments

@simonexmachina
Copy link

Hi there, I've been using moduleFor() and friends for a couple of months now since Stefan invited me to take a look. I've encountered lots of "gotchas" along the way and implemented workarounds as I've gone.

I think it would be good to have a discussion about these and, where we don't remove the gotcha, document some use cases that address these issues. Here's some examples:

  • Added call to container.reset() in teardown() function stefanpenner/ember-app-kit#465 and potential container variable leek #3

  • The isolated container doesn't perform injections - you have to handle these manually

  • Calling model.serialize() on a DS.Model instance fails unless you container.register('serializer:application', DS.JSONSerializer), and all of the transforms (eg. transform:string etc).

  • Using a FixtureStore only in testing is a challenge, the solution we have is:

    // adapters/application.js
    if (Ember.testing) {
      Adapter = DS.FixtureAdapter;
    }
    else {
      Adapter = DS.RESTAdapter.extend({...
    
    // test/helpers.js
    export function fixtureStore(container) {
      container.register('store:main', DS.Store);
      container.register('serializer:application', DS.JSONSerializer);
      container.register('adapter:application', DS.FixtureAdapter);
      container.register('transform:boolean', DS.BooleanTransform);
      container.register('transform:date', DS.DateTransform);
      container.register('transform:number', DS.NumberTransform);
      container.register('transform:string', DS.StringTransform);
      container.injection('route', 'store', 'store:main');
      container.injection('model', 'store', 'store:main');
      return container.lookup('store:main');
    }
    

    Pretty verbose :)

  • The resolver seems doesn't resolve models, so you need to manually resolve them in tests where you need them:

    export function loadCampaignModels(container) {
      var needs = [
        'model:campaign', 'model:agency', 'model:campaign-type', 'model:advertiser',
        'model:brand', 'model:product'
      ];
      resolve(needs, container);
      loadMediaPlanModels(container);
    }
    
    export function loadMediaPlanModels(container) {
      var needs = [
        'model:mediaplan', 'model:lineitem'
      ];
      resolve(needs, container);
    }
    
    export function loadLineItemModels(container) {
      var needs = ['model:property', 'model:market',
        'model:audience', 'model:language',
        'model:targeting', 'model:dealtype'];
      resolve(needs, container);
    }
    
    export function resolve( needs, container ) {
      var resolver = Resolver['default'].create();
      resolver.namespace = {
        modulePrefix: 'mn'
      };
      for (var i = needs.length; i > 0; i--) {
        var fullName = needs[i - 1];
        container.register(fullName, resolver.resolve(fullName));
      }  
    }
    
  • Here's another example from my initial feedback on moduleFor()

I don't know enough about the concerns here, but IMHO I think it'd be good to get the isolatedContainer to inherit from the top-level container (which has the injections and resolver) in some way. I think at the very least the isolatedContainer should have a working resolver and have the same injection rules as the application container. Can we copy these over when we create the isolatedContainer?

@adambard
Copy link

Just here to add another vote for this. This library has a lot of promise, but isolatedContainer (apparently) disregarding injections is making testing a total bitch. I thought one of the benefits of DI was to make testing easier?

@Turbo87
Copy link
Member

Turbo87 commented Oct 14, 2017

this no longer seems relevant, closing due to age

@Turbo87 Turbo87 closed this as completed Oct 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants