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

How to convert unit tests with injections? #64

Open
alexander-alvarez opened this issue Nov 14, 2017 · 5 comments
Open

How to convert unit tests with injections? #64

alexander-alvarez opened this issue Nov 14, 2017 · 5 comments
Labels

Comments

@alexander-alvarez
Copy link
Contributor

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({});
    });

});
@rwjblue
Copy link
Member

rwjblue commented Nov 14, 2017

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 ember-qunit@3.0.0 and use setApplication (like ember-cli/ember-cli#7437). Can you double check if using setApplication properly adds router:main to the registry?

@rwjblue
Copy link
Member

rwjblue commented Nov 14, 2017

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)...

@rwjblue rwjblue added the bug label Nov 14, 2017
@rwjblue
Copy link
Member

rwjblue commented Nov 17, 2017

@alexander-alvarez - Any chance you could whip up a demo repo that I could use to step through?

@alexander-alvarez
Copy link
Contributor Author

No problem... I'll try to set something up Monday night

@alexander-alvarez
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants