11
votes

I am trying Karma for the first time, and after several hours I still can't get it to work.

When I run the test by typing karma start karma.conf.js in the terminal, the browser window opens and displays the following (I have also tried with Chrome with the same result):

enter image description here

This is the terminal output:

29 07 2015 16:27:12.835:INFO [karma]: Karma v0.13.3 server started at http://localhost:9876/
29 07 2015 16:27:12.852:INFO [launcher]: Starting browser Firefox
29 07 2015 16:27:15.866:INFO [Firefox 33.0.0 (Windows 7 0.0.0)]: Connected on socket HA1RSN-QsWuAO7NIAAAA with id 26755366

My karma.conf.js file is located at the root of my Node.js project and looks like this:

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine'],
    files: [
        'tests/unit/test.js'
    ],
    exclude: [],
    preprocessors: {},
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: false,  
    browsers: ['Firefox'],
    singleRun: false
  })
}

My test.js file looks like this (example test from a book, my actual tests will the Angular.js tests):

describe("First Test", function () {
    var counter;
    beforeEach(function () {
        counter = 0;
    });
    it("increments value", function () {
        counter++;
        expect(counter).toEqual(1);
    });
    it("decrements value", function () {
        counter--;
        expect(counter).toEqual(0);
    });
});

I'm using Node.js version 0.12.05.

I appreciate any help as I feel really lost here.

1

1 Answers

14
votes

You need to trigger a test run, if you want it to execute. There are two ways to do this

  1. Run karma run karma.conf.js in a second terminal window in the same working directory
  2. Change the option singleRun to true, this way it will start, execute the test and then exit.