Set Up Jasmine and Karma

Install karma-cli on your machine

npm install karma-cli -g

Add jasminekarma and karma-jasmine to your project’s dependencies

npm install jasmine karma karma-jasmine --save-dev

Create a karma configuration file

karma init

It starts init script where you can go with suggested settings. Once it has finished, you should manually update your project files in karma.conf.js, like so

files: [

That configuration assumes that your main application logic is stored in app folder, and your Jasmine unit tests are located in the tests directory.

If your application depends on AngularJS you have to consider adding additional paths


In order to test if everything is setup properly, add your first test to the test directory

describe('first sample test', function() {
  it('should be true', function() {

and run karma

karma start

You should see that your test passed as below


To stop karma, hit CTRL+C


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s