Testing Angular 2.0 RC1 Applications
As mentioned on Friday, there's been quite a bit that's changed with Angular 2 between its Beta 9 and RC 1 releases. This article is an update to the Testing Angular 2 Applications I wrote in March. That tutorial was based on Angular 2.0 Beta 9. Rather than simply updating that tutorial and blog post for 2.0 RC1, I decided to create a new version for posterity's sake. The 2.0 Beta 9 version will remain on my blog and I've tagged the source on GitHub.
If you've already read the first version of Testing Angular 2 Applications, checkout the diff of the Asciidoctor version to see what's changed.
What you'll build
You'll learn to use Jasmine for unit testing controllers and Protractor for integration testing. See Angular 2's 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, checkout the testing-start
branch, and install its dependencies.
git clone https://github.com/mraible/angular2-tutorial.git cd angular2-tutorial git checkout testing-start npm install
If you haven't completed the Getting
Started with Angular 2.0 RC1 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/.