sar
sar

Reputation: 1287

karma is not executing test case

I am new to karma. I am not able to execute test case . I have following setup.

      karma.config.js

 module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
  'angular.js','angular-mocks.js' ,'tests/firstTest.js'
],


// list of files to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
  });
};

firstTest.js

           describe("First Test", function () {
// Arrange (set up a scenario)
var counter;
beforeEach(function () {
counter = 0;
});
it("increments value", function () {
// Act (attempt the operation)
counter++;
// Assert (verify the result)
expect(counter).toEqual(1);
})
it("decrements value", function () {
// Act (attempt the operation)
counter--;
// Assert (verify the result)
expect(counter).toEqual(0);
})
});

I am getting following output when use 'karma start karma.config.js' command.

INFO[karma]:karma v0.12.31 server  started at http://localhost:9876/
INFO[launcher]:Starting broswer Chrome
INFO[Chrome 41.0.2272 (windows 7)]: connected on socket ...... with id 98...

but nothing happens after this and in chrome browser it just display

karma v0.12.31 Connected
chrome  41 (windows 7 ) executing.

I am able to see my firstTest.js loaded in browser. I really don`t know what is wrong in my code. I am referring 'Pro AngularJS' book. Please let me know what wrong I am doing.

EDIT

I am also getting some error in browser console.

Uncaught SyntaxError: Unexpected identifier context.html 28
Uncaught TypeError: Cannot read property 'config' of undefined adapter.js 322
Uncaught TypeError: Cannot read property 'loaded' of undefined   context.html

Upvotes: 1

Views: 1421

Answers (1)

Eddie D
Eddie D

Reputation: 349

"Karma start" appears to just start the server but not run tests. Try running "karma start" in one console, and "karma run" in another console to actually execute the tests. You should see output in both console windows related to the test execution.

Alternatively, you can edit the karma.conf.js file to include "singleRun":true. Then when you use karma start, it will boot the browser, run the tests, and close the browser all in one action.

Upvotes: 3

Related Questions