How can I get moduleFor() to resolve a custom factory registered with the container in an initializer?


#1

How can I get moduleFor() to resolve a custom factory registered with the container in an initializer?

I’d like to create a custom class, app/validations/user that gets resolved out of the container. I’ve set up the initializer to register this class with the container.

import UserValidation from 'demo/validations/user';

export function initialize(application) {
  application.register('validations:user', UserValidation, { singleton: false });
  application.inject('route', 'userValidation', 'validations:user');
}

However, in test mode, moduleFor() doesn’t run this initializer so I get “Attempting to register an unknown factory: ‘validations:user’”

import { moduleFor, test } from 'ember-qunit';

moduleFor('validations:user', 'Unit | Validations | user', {
  needs: []
});

test('no options', function(assert) {
  assert.ok(true);
});

Anyone know what I am missing? Thank you!