1
votes

I have a problem to run my tests in Webstorm 8, here is my conf file :

Here is my AngularJS controller :

angular.module('monApp').controller('DashboardCtrl', [
    '$scope', function ($scope) {
        'use strict';

        $scope.foo = 'bar';
    }
]);

And my test file :

describe('Controller: DashboardCtrl', function () {
    'use strict';

    var DashboardCtrl,
        scope;

    beforeEach(module('monApp'));

    beforeEach(inject(function ($controller, $rootScope) {
        scope = $rootScope.$new();
        DashboardCtrl = $controller('DashboardCtrl', {
            $scope : scope
        });
    }));

    it('dashboard should be defined', function () {
        expect(scope.foo).toBeDefined();
        expect(scope.foo).toBe('bar');
    });
});

These are very simple, I followed steps of many tutorials, first installed node, then install karma with npm install, and when i run karma with karma start my.conf.js the test pass but it shows Empty test suite.

I precise that in my project, I just have 5 files :

  • angular.js
  • angular-mocks.js
  • the controller
  • test file
  • conf file

In the config file, i have added these 4 files with :

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

When I try to throw the test by right-click I get an error telling : describe is not defined.

Thanks.

2
It's most likely that angular-mocks.js is missing, check paths and if it's loading in your browser - maurycy
I had problems with that first it displayd Warning, so I change the basePath in the config file, and all my files seem loaded now. - matt2mi

2 Answers

1
votes

I tried to restart from scratch and it appears that my instantiation of my app module wasn't fine, this is better :

var app = angular.module('monApp', []); 
app.controller('DashboardCtrl', ['$scope', function ($scope) { .... 

And the first problem "empty test suite" was due to wrong basePath in the config file. Anyway, thanks for your answers !

0
votes

Your my.conf.js must contain :

frameworks: ['jasmine']

And Karma need the bridge to Jasmine framework to be installed :

npm install karma-jasmine --save-dev

By default, karma loads all installed plugins which are starting with "karma-".