I'm sure this has something to do with angular-mock.js but I cant figure what I need to do as everything seems to be fine. I'm just going by the default setup from angular-seed app. Please help get rid of the problem
karma.conf.js
module.exports = function(config){
config.set({
basePath : '../',
files : [
'bower_components/angular/angular.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-mocks/angular-mocks.js',
'app/js/**/*.js',
'test/unit/**/*.js'
],
autoWatch : true,
frameworks: ['jasmine'],
browsers : ['Chrome'],
plugins : [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine'
],
junitReporter : {
outputFile: 'test_out/unit.xml',
suite: 'unit'
}
});
};
controllers.js
'use strict';
/* Controllers */
var app = angular.module('myApp.controllers', []);
app.constant('RESTURL', 'http://'+ location.hostname + ':8003');
app.controller('MainCtrl', ['$scope', 'dataService', 'flash', 'mySharedService','facetSearchService', 'facetSelectionService', 'RESTURL', function($scope, dataService, flash, sharedService, facetSearch, facet, RESTURL) {
$scope.RESTURL = RESTURL;
$scope.loading = true;
$scope.data = null;
$scope.resultCount = 0;
$scope.currentPage = 0;
$scope.pageSize = 10;
....
])}
controllerSpec.js
'use strict';
/* jasmine specs for controllers go here */
describe('controllers', function(){
beforeEach(module('myApp.controllers'));
it('should test MainCtrl', inject(function($controller) {
//spec body
var scope = {},
ctrl = $controller('MainCtrl', {$scope:scope});
expect($scope.RESTURL).toBe('http://'+ location.hostname + ':8003'));
}));
});
Project file structure:
I trust you ran "bower install" to install the dependencies?
The paths to bower_components are incorrect. A basepath of "../" will make karma look in the root of your project but your bower_components are in your "app" folder. The "files" in karma.conf need to be prefixed with "app".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With