Testing Angular 2 Applications
Click here to see an updated version of this tutorial that's been upgraded for Angular 2.0 RC1.
This article is the second in a series about learning Angular 2. It describes how to test a simple Angular 2 application. In a previous article, Getting Started with Angular 2, I showed how to develop a simple search and edit feature. In this tutorial, I did my best to keep the tests similar to last year's Testing AngularJS Applications so you can compare the code between AngularJS and Angular 2.
What you'll build
You'll learn to use Jasmine for unit testing controllers and Protractor for integration testing. Angular's documentation has a good guide to unit testing if you'd like more information on testing and why it's important.
The best reason for writing tests is to automate your testing. Without tests, you'll likely be testing manually. This manual testing will take longer and longer as your codebase grows.
What you'll need
- About 15-30 minutes.
- A favorite text editor or IDE. I recommend IntelliJ IDEA.
- Git installed.
- Node.js and npm installed. I recommend using nvm.
Get the tutorial project
Clone the angular2-tutorial repository using git and install its dependencies.
git clone https://github.com/mraible/angular2-tutorial.git cd angular2-tutorial npm install
If you haven't completed the Getting
Started with Angular 2 tutorial,
you should peruse it so you understand how this application works.
You can also simply start the app with npm start
and view it in your browser at http://localhost:5555/.