You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Angular 1 unit tests fail with Angular 2 components using downgradeComponents #14263
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
We are using the current documented way of downgrading Angular 2 components with the UpgradeModule for use in an Angular 1 hybrid app, specifically an angular 1 component. We have unit tests that uses $compile to create an element with our angular 1 component which itself uses a downgraded angular 2 component, which is downgraded with downgradeComponent in the static upgrade as opposed to the one in UpgradeAdapter. This works with interacting with the app in the browser. However, an error pops up in the unit test that says Error: [$injector:unpr] Unknown Provider $$angularInjectorProvider.
A possible hacky solution here was to call beforeEach(angular.mock.module('$$UpgradeModule')). While the error is gone, the unit tests still fail because changes are not being detected in the downgraded angular 2 component.
There seems to a fix in 2fc0560 that fixed the issue in #5462, but that is for the UpgradeAdapter and not for UpgradeModule.
Expected behavior
Existing angular 1 unit tests should be able to test angular 1 components that have angular 2 downgraded components without failing.
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
Angular version: 2.0.X
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
Language: [all | TypeScript X.X | ES6/7 | ES5]
Node (for AoT issues):node --version =
Reacted by Jun Woo Shin, Christopher Sang, Colin Nichols, Sergey Shevchenko, Dimitar Kanev, Eudes Petonnet-Vincent, bdunkz, louwie17, florianpanaseer, Mukundan Kidambi and 28 more
I have the same problem when trying to unit test ng1 services that have ng2 dependencies registered with downgradeInjectable()
have to mock such ng2 dependencies in order to make existing tests pass, which makes migration from ng1 to ng2 more painful
For the time being, the simplest approach is to bootstrap a "mini hybrid app" for each test (which is less than ideal for several reasons). Testing with ngUpgrade will be improved much once #16848 is merged 😃
Activity
jwoos commentedon Feb 3, 2017
I have also experienced this issue
sshev commentedon Feb 7, 2017
I have the same problem when trying to unit test ng1 services that have ng2 dependencies registered with
downgradeInjectable()have to mock such ng2 dependencies in order to make existing tests pass, which makes migration from ng1 to ng2 more painful
dkanev commentedon Feb 7, 2017
+1
ronwang01 commentedon Feb 14, 2017
+1
djpark commentedon Feb 15, 2017
+1
idoglik6 commentedon Mar 1, 2017
+1
bh86 commentedon Mar 1, 2017
+1
ninaneter commentedon Mar 1, 2017
+1
moanrose commentedon Mar 13, 2017
+1
amosuro commentedon May 12, 2017
+1 the documentation is great but this issue is making the idea of gradually migrating to Angular very difficult.
nikolay-lesko commentedon May 15, 2017
+1
gkalpak commentedon Jul 4, 2017
For the time being, the simplest approach is to bootstrap a "mini hybrid app" for each test (which is less than ideal for several reasons). Testing with ngUpgrade will be improved much once #16848 is merged 😃
gkalpak commentedon Dec 15, 2017
I am going to close this. Let's track the addition of test helpers for ngUpgrade in #16848.
angular-automatic-lock-bot commentedon Sep 13, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.