Angular 1.x testing are good for angular 2? - angularjs

I'm starting a new app that is made with angular 1.x, and I'm thinking about changing to angular 2. Do you recommend me to do that?
A part of that question, the most important one is that I want to know if Angular testing using Karma and Protractor are good for Angular 2. If I switch to Angular 2, can I run the tests to verify if the functionality still being the same?
I don't have the tests yet, so if I have to do it in a special way in order to be able to do that is welcome too.

Related

Upgrade AngularJS to Angular 6 in Cordova App

I have a Cordova app built using Angular 1 i.e. Angular JS. How I can upgrade the app yo latest angular version.
Will it require complete code re-write to TypeScript (TS)??
TypeScript is not a requirement for writing Angular 2+. However, Angular 2-7 does not have much in common with AngularJS as it doesn't have the same architecture or components. For example, from what i've read about it, AngularJS used a MVC model, Angular2+ does not.
So to answer your question, you will indeed need to rewrite most of your application. Going from Angular 2 to 7 is much easier as not much has changed.

Use Angular 2 pages in Angular 1

Currently we have application developed in Angular 1.X but we don't want to migrate from Angular 1.X to Angular 2, Since it is very wast application it will require more effort. We want other way around . Can we use Angular 2 features within Angular 1.X Application. In future whichever pages is created should be in Angular 2 but need to be worked side by side with Angular 1.X .. Like calling new route or new component from Angular 2 from Angular 1.X. Please let me know whether its possible or not.
Thanks
Kind of. What you are looking for is an Angular Hybrid app. Here's an article to help with what you are looking for.
Yes, it is possible.
You can use the new angular components/modules in a legacy angular application (downgrading) or you can use legacy components in the a new angular application (upgrading).
There is a section on the angular webpage describing all this. Direct link is here
https://angular.io/guide/upgrade#using-angular-components-from-angularjs-code

Planning to use angular 2, but our existing app is using angular 1.x. Is there any documentation on using angular 2 along with angular 1.x?

We will not be able to re write our app now also we don't want to create a new app for just angular 2. Trying to find a way to use both so that we can migrate slowly.
on Angulars official site they have docs for converting form angular 1 to angular 2 located here angular.io this will probably be your best bet rather than mixing angular one with angular 2.

NgUpgrade: Can I use Angular2 Component in app bootstrapped with `ng-app`?

If I want to use the Angular-upgrade module in my Angular1 application it seems like I have to bootstrap the whole app using Angular2's bootstrapping, including ditching the ng-app declaration. My team is very interested in graduating our apps' components over time to Angular 2, but touching the bootstrapping is a little too impactful for us at this moment.
In order to use the Upgrade Adapter do I have to transform the way my app bootstraps in order to use an Angular2 component? Is there anyway to use an Angular2 component in a full Angular1 app?
Here's a great article that describes multiple scenarios for upgrading, but none of them leave the app bootstrapped as a normal Angular1 app.
Short answer is No.
From angular documentation
Pure Angular 1 applications can be bootstrapped in two ways: By using
an ng-app directive somewhere on the HTML page, or by calling
angular.bootstrap from JavaScript. In Angular 2, only the second
method is possible - there is no ng-app in Angular 2. This is also the
case for hybrid applications. Therefore, it is a good preliminary step
to switch Angular 1 applications to use the JavaScript bootstrap
method even before switching them to hybrid mode.
For better understanding how upgrade works read this article from official documentation https://angular.io/docs/ts/latest/guide/upgrade.html

Difference between JASMINE_ADAPTER and ANGULAR_SCENARIO_ADAPTER in Karma

I want to know what's the difference between JASMINE_ADAPTER and ANGULAR_SCENARIO_ADAPTER ?
Because i'm using yeoman with angular and i've got two karma config files one with JASMINE_ADAPTER and other with ANGULAR_SCENARIO_ADAPTER.
Thanks for your answers.
Tom
Jasmine and Angular Scenario are two different things. Angular Scenario is simply built to look like Jasmine testing code. They both use describe(), it(), and have similar "framework" styles.
The fundamental difference is that Jasmine is more Javascript-testing oriented while Angular Scenario is more DOM oriented.
For example, Angular Scenario can be used to test whether or not your AngularJs code correctly creates DOM objects, while Jasmine tests the Javascript itself.
A big difference between the two is that Angular Scenario allows you to open a "browser" (as a frame) and fully load the page, whereas Jasmine just loads Javascript.
browser().navigateTo("http://www.stackoverflow.com");
can only be done in Angular Scenario.
Similarly, Angular Scenario can manipulate DOM objects. You can fill out forms and select objects, like:
input("username").enter("my_username");
input("password").enter("my_password");
element(".submitButton").click();
I highly recommend you look at:
http://docs.angularjs.org/guide/dev_guide.e2e-testing and http://pivotal.github.io/jasmine/

Resources