Backbone to Angular Part II

June 17, 2014

17 June 2014 - Redwood City, CA

Lets talk about tests. Yes, tests. Some of you might love the phrase, and some of you may hate it. When it comes to refactoring, however, if you’re not using tests you’re pretty much going to screw yourself somewhere along the road. Even if you’re not a huge fan of TDD, doing test-driven refactors are going to save you a lot of hair pulling down the road. Lets get started.

Tools for tests

Angular was built with the idea that testing needed to be an integral part of the framework. Nothing is merged into core without having tests to go with it. This is imperative for dynamically-typed functions, like javascript, if you want to save yourself the overhead of error checking everything under the sun in your actual codebase.

We have two primary types of tests and test-runners that the angular team recommends. Karma and Protractor. Both are nessecary: Karma for unit-tests, and karma for end-to-end tests. First, lets get started with Karma and unit-testing.

Setting up Karma

If you don’t have karma already in your package.json run:

npm install --save-dev karma

then move into where you’d like to keep all of your tests. For this example, we’ll follow what they do in angular-seed and place a sibling tests folder on the same level as the client-facing app folder.