Introduction to Karma

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 10 years ago
Updated 5 years ago

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

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,

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.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today