Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Introduction to Karma

    John LindquistJohn Lindquist

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

    webstormWebStorm
    karmaKarma
    javascriptJavaScript
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss