Reputation: 347
this is part of my configuration file karma.conf.js:
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '../',
// list of files / patterns to load in the browser
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/js/app.js',
'app/js/controllers/*.js',
'app/js/services/*.js',
'test/unit/*.js'
],
and this is my folders struct:
This is app.js file:
/**
* Created by Pietro on 30/12/15.
*/
'use strict';
var drfmApp = angular.module('drfmApp', [
'ngRoute','drfmControllers','ngCookies'
]);
drfmApp.config(['$routeProvider','$locationProvider',
function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'views/login.html',
controller: 'LoginController'
}).
when('/login', {
templateUrl: 'views/login.html',
controller: 'LoginController',
}).
when('/register', {
templateUrl: 'views/register.html',
controller: 'RegisterController',
}).
when('/dashboardESCO', {
templateUrl: 'views/dashboard_esco.html',
controller: 'DashboardESCOControllers'
}).
when('/dashboardRetailer', {
templateUrl: 'views/dashboard_retailer.html',
controller: 'DashboardRetailerControllers'
}).
when('/dashboardAggregator', {
templateUrl: 'views/dashboard_aggregator.html',
controller: 'DashboardAggregatorControllers'
}).
otherwise({
redirectTo: '/login'
});
}]);
drfmApp.run(['$rootScope', '$location', '$cookieStore', '$http',
function($rootScope, $location, $cookieStore, $http) {
// keep user logged in after page refresh
$rootScope.globals = $cookieStore.get('globals') || {};
if ($rootScope.globals.currentUser) {
$http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line
}
$rootScope.$on('$locationChangeStart', function (event, next, current) {
// redirect to login page if not logged in and trying to access a restricted page
// $ è jQuery
var restrictedPage = $.inArray($location.path(), ['/login', '/register']) === -1;
var loggedIn = $rootScope.globals.currentUser;
if (restrictedPage && !loggedIn) {
console.log('Run Config: User not logge in or trying to access a restricted web page')
$location.path('/login');
}
});
}]);
I'm trying to run a simple unit test file like this (using Karma and Jasmine):
'use strict';
/* jasmine specs for controllers go here */
describe('Drfm controllers', function () {
beforeEach(module('drfmControllers'));
it('DUMMY TEST', function () {
expect(3).toBe(3);
});
});
where drfmApp is the name of the main module in app.js file
This is where drfmControllers is defined (in controllers.js):
/**
* Created by Pietro on 07/01/16.
*/
'use strict';
var drfmControllers = angular.module('drfmControllers', []);
drfmControllers.controller('DashboardESCOControllers', ['$scope',
function($scope) {
$scope.dashboard = "ESCO Dashboard";
}
]);
drfmControllers.controller('DashboardRetailerControllers', ['$scope',
function($scope){
$scope.dashboard="Retailer Dashboard";}
]);
drfmControllers.controller('DashboardAggregatorControllers', ['$scope',
function($scope){
$scope.dashboard="Aggregator Dashboard";}
]);
But I always have this error:
Error: [$injector:nomod] Module 'drfmControllers' is not available! You either misspelled the module name or forgot to load it.
If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.4.8/$injector/nomod?p0=drfmControllers at /Users/Pietro/repos/drfmcockpit/app/bower_components/angular/angular.js:68
I read about the order of the *.js files in karma configuration file: but seems it is according to this rule [see "files" at the start of the question].
Thanks to everybody
UPDATE SOLUTION: changing the conf file with this:
// list of files / patterns to load in the browser
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/js/app.js',
'app/js/controllers/controllers.js',
'app/js/controllers/LoginController.js',
'app/js/controllers/RegisterController.js',
'test/unit/*.js'
],
It runs well. Seems something in files inspections. I don't know well..
Upvotes: 2
Views: 1474
Reputation: 12862
You haven't set basePath
in you configuration options. By default, it is equal to ''
. In it's turn, empty string as a basePath
value, makes it relative to the configuration file directory. It is described here:
If the basePath is a relative path, it gets resolved to the directory where the configuration file is located
That means that either you should set basePath
value to an absolute path, or you should change your files paths to relative, like:
files: [
'../app/bower_components/angular/angular.js',
'../app/bower_components/angular-route/angular-route.js',
'../app/bower_components/angular-mocks/angular-mocks.js',
'../app/js/app.js',
'../app/js/controllers/*.js',
'../app/js/services/*.js',
'unit/*.js'
],
Upvotes: 1