Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 986 of the free egghead.io lessons, plus get Tools content delivered directly to your inbox!

Existing egghead members will not see this. Sign in.

Introduction to Karma

2:45 Tools lesson by

A quick tutorial covering installing Karma and running tests from the command line and Webstorm.

egghead.io comment guidelines


A quick tutorial covering installing Karma and running tests from the command line and Webstorm.


For some reason, when adding the karma-jasmine library globally (as to get auto complete working) it doesn't seem to recognize library as the 'describe' , 'it' , 'beforeEach' etc commands are still underlined (not recognized)

I am using with PHPStorm 7.1.1 (doubt it is related to PHPStorm but never know)

In reply to egghead.io
Rob Murtha

I found the same issue and installed the standalone jasmine 1.3.1 and referenced it as a global library. Take a look at the jasmine source code right at 2:11 in the video it matches the jasmine 1.3.1 source.

In reply to Mike

I had to add a plugin section to the config file to get rid of the manual interaction with the browser.

plugins : [

In reply to egghead.io

John Lindquist: ...karna only takes one minute to set up after you've installed node into NPM and npm install -g karma, because all you have to do is switch over to WebStorm or use the terminal. I'm going to use the one in WebStorm.

Say, karma init

Once that's installed, I'm going to use Jasmine for my testing, no require JS. I use Chrome. I'll define test file paths later and I don't want to exclude anything. I'm not going to have Karma watch for file changes because I'll have WebStorm do that for me.

Then the file is generated. You can see when I double clicked on the folder that Karma is in there, and it's ready to run. I can actually simply right click on it now in WebStorm and say, "Run Karma." It will run and nothing. It didn't run anything.

Basically, let's define our first file. We'll say, "Test." We'll say, "Hello JS." Then just switch over to our project, we'll do a new JavaScript file, say, "Test hello."

This will generate this file. I'll say, "Describe." I'll describe hello. We want it...

It should work. From there, we say, "Expect true to be false" because we want it to fail once. We want control-R to rerun, and expected true to be false. Then all of this simply changed to true. Then rerun and we have our first passing test.

One thing you probably noticed is that I got auto-complete in here and that's because I defined in my JavaScript libraries, in my preferences. I defined something called a Karma Jasmine library, which if you look at it, it's under my user local share NMP node modules. I just added that in here, which allows me to say whenever...

I just enable this check box. That adds this JavaScript library to your project so that you get auto-complete to that library. Even though I don't have Karma, I have that JavaScript file in my project, I can actually control click on this and it will navigate to that file in my path.

You can see up here that that's actually that actual file. We have our first test running and Karma was installed. Basically, I'm just going to be adding files to this list of files to keep on testing them.

If you want to use the command line to run Karma tests, just go to the configuration. It will show you the steps. It will say, "Starting Karma. Karma start," and some of the arguments you can pass in for the customizations you want to do.

Joel's Head
Why are we asking?