Appendix A. Setting up Karma

 

Karma is a JavaScript test runner created by the AngularJS team. It’s important to note that it’s not a testing framework. It allows you to specify information about your testing environment, such as which browser(s) to use, which files to include, and so on. You then specify which testing framework you want to use (Jasmine, in our case) and write your tests using that particular framework.

Install Node.js and Node Package Manager (npm)

First things first. If you haven’t yet installed Node.js, stop! Here are a couple resources to get the ball rolling:

Install packages

If you do have Node.js and npm, welcome! First, install karma-cli globally so you have access to it in any directory:

npm install -g karma-cli

Next, make sure you’re in the angello directory, and then install karma and save it as a dev dependency:

npm install karma --save-dev

Now, install your necessary plugins. These include the plugins for your testing framework of choice as well as any browsers that you need to integrate with. In this book, we use Jasmine as our testing framework and Chrome for our browser.

npm install karma-jasmine karma-chrome-launcher --save-dev

Initialize Karma

Now that you have all the dependencies installed, it takes only a single command in the terminal to initialize the Karma configuration:

karma init

Use Karma