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
Unit testing ngUpgrade applications #5462
Comments
Ping @juliemr |
+1 We should find a way to inject scopes for ng1 sub components. I get the following error:
|
Any changes on this issue? We're trying to get our Angular 1 unit tests to work with the upgrade adapter in place, downgrading now Angular 2 services to Angular 1. We are getting |
Hi! 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. |
If it works for you then we might close this issue. |
That's pretty neat @yjaaidi. Ideally there'd be some sugar for this in ngUpgrade though, integrating it with angular-mock better. I'm working on some updates to the upgrade guide and I'll see if I can add this in as a possible pattern to use. |
Cool! Thanks @teropa |
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462, angular#9643, angular#9649
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462, angular#9643, angular#9649
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462, angular#9643, angular#9649
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462, angular#9643, angular#9649
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462, angular#9643, angular#9649
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462, angular#9643, angular#9649
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462, angular#9643, angular#9649
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462, angular#9643, angular#9649
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462, angular#9643, angular#9649
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
Any update on this @petebacondarwin ? In which Angular 2 version can we use this? Thanks |
This is the PR to follow: #12675 |
Thank you @petebacondarwin 👍 |
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462
I'm not clear on how to get my NG1 unit tests to start working again. My NG1 unit tests are using angular.mock, everything works fine until a dependency is NG2 (for example a downgraded NG2 service using another standard NG2 service). Is there any way to get this working? Do I need to wait for a later release? The documentation on angular.io doesn't address my use case. For now, leaving all my NG1 tests disabled. |
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462, angular#12675
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462, angular#12675
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462, angular#12675
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462, angular#12675
- New method `UpgradeAdapter.registerForNg1Tests(modules)` declares the Angular 1 upgrade module and provides it to the `angular.mock.module()` helper. This prevents the need to bootstrap the entire hybrid for every test. Closes angular#5462, angular#12675
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
How does one write unit tests for hybrid applications that have a mixture of Angular 1 and Angular 2 components?
I've been able to run a test suite that has some tests for ng1 and some for ng2, but I've achieved this by always mocking out cross-framework dependencies and using
beforeEachProviders
/injectAsync
for Angular 2 components, andangular.mock.module
/angular.mock.inject
for Angular 1 components. But I don't see a way to test a hybrid with either of these two approaches.For a minimal example app demonstrating the issue, see https://github.com/teropa/ng1-2-hybrid-unit-tests
The text was updated successfully, but these errors were encountered: