Karma config file for Angular / requireJS Project

There are many KarmaJS config files, but this is my config file

karmaJS logo

To develop an Angular project with an Test-driven development (TDD) approach, using a software like KarmaJS is essential. My Angular project uses RequireJS to load, so Karma needs to be loaded with RequireJS too.


Install Karma and some plugins via Node:

# Install Karma:
$ npm install karma --save-dev

# Install plugins that your project needs:
$ npm install karma-jasmine karma-chrome-launcher --save-dev

RequireJS Plugin

This Karma plugin is a Adapter for the RequireJS framework - there is a very good documentation link on the gitub page - https://github.com/karma-runner/karma-requirejs

Jasmine Plugin

This Karma plugin is a adapter for Jasmine testing framework. Jasmine is a framework for testing JavaScript code - https://github.com/karma-runner/karma-jasmine

PhantomJS Plugin

This Karma plugin launches the headless PhantomJS Browser. Karma will launch PhantomJS in the terminal - https://github.com/karma-runner/karma-phantomjs-launcher

Bonus: Karma Spec Reporter

I liked the output from this test reporter software. The only drawback was a little issue with filtering the output (issue #19) - but it can be kinda fixed with a config parameter. Don’t forget to activate the new Spec Reporter - https://github.com/mlex/karma-spec-reporter

Tips & Tricks

I had a few troubles getting Karma up and running, here are the things I’ve learned while setting everything up.