ember-qunit-codemod
ember-qunit-codemod copied to clipboard
How to convert unit tests with injections?
I have some injections on my controller (inside of an engine) which worked, but after running the codemod I'm getting errors:
Attempting to inject an unknown injection: 'router:main
I imagine it's because the registry in the new API is isolated?
Should we be manually registering services, or is there a different desired change?
const resolver = engineResolverFor('my-engine');
module('Unit | Controller | my controller', function(hooks) {
setupTest(hooks, {
resolver
});
test('injection of services', function(assert) {
// error occurs here
let controller = this.owner.factoryFor('controller:my-controller').create({});
});
});
I need to see how this actually worked before, I'm not sure the best path forward here.
I believe that this might have been fixed automatically when using [email protected] and use setApplication (like https://github.com/ember-cli/ember-cli/pull/7437). Can you double check if using setApplication properly adds router:main to the registry?
On second thought, I'm not 100% sure if we also need changes to the engineResolverFor helper method also (and internally create the engine instance exactly how ember itself creates them normally)...
@alexander-alvarez - Any chance you could whip up a demo repo that I could use to step through?
No problem... I'll try to set something up Monday night
been working on https://github.com/alexander-alvarez/ember-qunit-engine-injection-repro/commits/master
So I don't know if it's just not my day, but I'm getting a lot of weird behavior on a clean branch. I can't seem to test with a live service injection into a controller in the old mode, as well as the new mode. https://github.com/alexander-alvarez/ember-qunit-engine-injection-repro/blob/master/tests/unit/controllers/application-test.js#L10
Except for registering models (how should we do this ?) it seems the new style is working https://github.com/alexander-alvarez/ember-qunit-engine-injection-repro/blob/master/tests/unit/controllers/controller-with-model-transformed-test.js
Sorry this isn't much help. Been an awfully head-scratchy night