Karma not executing any unit tests

21,383

Solution 1

My last answer was wrong (moving the JASMINE and JASMINE_ADAPTER lines below the angular.js lines). It fixed this particular problem, but created other issues. Instead, what I did to fix it was to specify only the angular-mocks file, instead of angular-*, like so:

   JASMINE,
   JASMINE_ADAPTER,
  'Vendor/angular-1.0.6/angular.js',
  'Vendor/angular-1.0.6/angular-mocks.js',
  'Vendor/json2/json2.js',
  'Vendor/jquery/jquery-1.8.2.js',
  'Vendor/amplify/amplify.js',
  'Scripts/main.js',
  'Test/unit/*.js'

Solution 2

I just had the same issue and I found that I had to set autoWatch = true before Karma would run the tests automatically.

Solution 3

Alternatively you can use exclude section in your karma.conf.js

exclude = [
  'Vendor/angular-1.0.6/angular-scenario.js'
];

Solution 4

I tried all above without success, until finally...

In my karma.conf.js I removed the requirejs dependency, eg:

    frameworks: ['jasmine', 'requirejs'],

to:

    frameworks: ['jasmine'],

Solution 5

In case you are trying to solve this issue using JASMINE and JASMINE_ADAPTER this is no longer supported (at least on Karma version 0.10.2).

Instead use:

frameworks: ['jasmine']

in your Karma config file. You can read about this here.

I also found that in my files array I had set included: false for a pattern. included is only used if you want to manually include your Javascript files (for example if you will be using require.js). If all your tests will be loaded from that pattern you will see a message similar to:

PhantomJS 1.9.2 (Linux): Executed 0 of 0 ERROR (0.151 secs / 0 secs)

since the file containing the tests is never included. Removing the included: false from the files array for my pattern fixed this since the default if included is not specified is true.

Share:
21,383

Related videos on Youtube

Darren
Author by

Darren

Polyglot developer with expertise in Flash, ActionScript, JavaScript, Lua, Ruby, C#, PHP and C/C++. My passions are APIs, automation and game development.

Updated on May 27, 2020

Comments

  • Darren
    Darren almost 4 years

    I seem to be having a problem getting my Jasmine unit tests to actually execute. I have verified that all my scripts are getting loaded by setting the logLevel to LOG_DEBUG. My unit test is identical to the services test @ https://github.com/angular/angular-seed/blob/master/test/unit/servicesSpec.js.

    Also, I have used Testacular (before it was renamed to Karma) and I don't recall having this issue. I seem to get Chrome to run, but I have to manually hit a "Debug" button. Even when I hit this button my tests don't run.

    System details:

    • Windows 7
    • Node v0.10.4
    • Chrome 26.0.14
    • Karma 0.8.5 (installed with 3 warnings -- 2 loss of precision and one 'no definition for inline function v8::Persistent v8::Persistent::New(v8::Handle)')

    Here's my module code (Scripts/main.js):

    angular.module('sb.services', []).value('version', '0.0.1').value('amplify', amplify);
    angular.module('sb.directives', []);
    angular.module('sb.filters', []);
    angular.module('sb.controllers', []).controller('SbController', [
        '$scope', 
        'amplify', 
        function ($scope, amplify) {
            $scope.message = 'Hello World! (amplify exists?=' + !!amplify + ')';
        }
    ]);
    angular.module('sb', [
        'sb.services',
        'sb.directives',
        'sb.filters',
        'sb.controllers'
    ]);
    

    Here's my spec (Test/unit/servicesSpec.js):

    'use strict';
    
    describe('my services', function () {
        beforeEach(module('sb.services'));
    
        describe('version', function () {
            it('should return current version', inject(function(version) {
                expect(version).toEqual('0.0.1');
            }));
        });
    });
    

    Here's my karma.conf.js file:

    // Karma configuration
    // Generated on Mon Apr 15 2013 20:56:23 GMT-0400 (Eastern Daylight Time)
    
    
    // base path, that will be used to resolve files and exclude
    basePath = '';
    
    
    // list of files / patterns to load in the browser
    files = [
      JASMINE,
      JASMINE_ADAPTER,
      'Vendor/angular-1.0.6/angular.js',
      'Vendor/angular-1.0.6/angular-*.js',
      'Vendor/json2/json2.js',
      'Vendor/jquery/jquery-1.8.2.js',
      'Vendor/amplify/amplify.js',
      'Scripts/main.js',
      'Test/unit/*.js'
    ];
    
    
    // list of files to exclude
    exclude = [
    
    ];
    
    
    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit'
    reporters = ['progress'];
    
    
    // web server port
    port = 9876;
    
    
    // cli runner port
    runnerPort = 9100;
    
    
    // enable / disable colors in the output (reporters and logs)
    colors = true;
    
    
    // level of logging
    // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
    logLevel = LOG_WARN;
    
    
    // enable / disable watching file and executing tests whenever any file changes
    autoWatch = false;
    
    
    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers = ['Chrome'];
    
    junitReporter = {
        outputFile: 'Test/out/unit.xml',
        suite: 'unit'
    };
    
    
    // If browser does not capture in given timeout [ms], kill it
    captureTimeout = 60000;
    
    
    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun = false;
    
    • fodma1
      fodma1 almost 7 years
      I guess I'm pretty late with this, but I think you'll have to set either singleRun or autoWatch to true.
  • Darren
    Darren about 11 years
    Thanks for the help rquinn, any idea why having all angular JS files included caused the tests not run?
  • Ryan Quinn
    Ryan Quinn about 11 years
    It is because of the angular-scenario file, which is used for end-to-end testing. I think there is a conflict between that and the angular-mocks file.
  • Darren
    Darren almost 11 years
    Thanks this helped me, I found could use exclude as below to skip the scenario file.
  • Steven Stark
    Steven Stark over 5 years
    This saved me! I had to include require before, and now that it's not needed it was preventing my tests from running.