Getting started with Karma for AngularJS Testing

Install NodeJS

  2. Install to your computer
  3. Ensure your npm command is run behind proxy server
  4. if your have any problems, please follow this instruction

Skipping create package.json

I will install module by my self, so package.json will not include in this article.

Install Karma

  1. npm install karma-cli -g
  2. npm install karma — save-dev
  3. npm install karma-jasmine — save-dev
  4. npm install karma-chrome-launcher — save-dev

Creating karma config file

  1. karma init karma.conf.js

Answer the prompts as follows:

  • Which testing framework do you want to use?

Hit return to accept the default value i.e. jasmine.

  • Do you want to use Require.js ?

Hit return to accept the default value i.e. no.

  • Do you want to capture any browsers automatically ?

Hit return to accept the default value i.e. Chrome.

  • What is the location of your source and test files ?

Enter the following value:


Don’t worry if you accidentally skipped this, we can directly edit the config file at a later stage.

  • Should any of the files included by the previous patterns be excluded ?

Hit return to accept the default value.

  • Do you want Karma to watch all the files and run the tests on change ?

Hit return to accept the default value. i.e. yes

The config file called karma.conf.js will be created in the root folder.

Creating test

  1. create file test.js into test directive
describe(“A suite”, function() {
     it(“contains spec with an expectation”, function() {

Execute test

karma start karma.conf.js


One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.