Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Injecting Angular 2 services into Angular 1's $controller #8757
Related issue: #6655
Per this related issue, in Angular 1 components the Angular 2 injector is resolved via
We unit test all of our Angular 1 controllers completely separate from the DOM for simplicity. We build them using
Our tests for controllers that inject downgraded Angular 2 components are all failing with
After reading the related issue, it appears that this is caused because ngUpgrade can't find the Angular 2 injector by walking the DOM tree because there IS no DOM tree.
Is it possible to still test controllers in isolation like this when ngUpgrade is in play?
I assume we will still need to call bootstrap on the document before running tests?
Interesting issue. Actually, you should not use angular mocks'
It's not documented yet but there are some clues in angular 2's source code.
1 - Your
Here's a plunker with the solution:
We also published a blog post about angular 2 migration on Wishtack. We will soon be filling the blog with more posts about angular 2 testing.
So you are telling me that we can't use
We seem to have gotten by this problem. First, we had to use:
To instantiate the module that is being bootstrapped before each test.
Then we added the ng2Injector to this module using a factory and a closure: