Currently, I am facing an issue while testing an Angular controller with Karma and Jasmine. The problem lies in loading the module from my main class.
The main class is named: admin.controller.js
angular.module('admin.module').controller('admin.controller', ['$scope', function ($scope) {
$scope.SaveChanges = function()
{
return true;
}
}]);
The test class is named: admin.controller.tests.js
describe('admin.controller tests', function () {
beforeEach(module('admin.module'));
var $controller = {};
beforeEach(inject(function (_$controller_) {
$controller = _$controller_;
}));
describe('$scope.SaveChanges', function () {
it('Should return true', function () {
var $scope = {};
var controller = $controller('admin.controller', { $scope: $scope });
expect($scope.SaveChanges()).toBe(true);
});
});
});
In my karma.conf.js
file, the specified files in my project are:
// list of files / patterns to load in the browser
files: [
'../TriAngular/scripts/angular.js',
'../TriAngular/scripts/angular-mocks.js',
'../TriAngular/app/admin/*.js',
'app/admin/*.js'
],
The file admin.controller.js
can be found inside ../TriAngular/app/admin
, while admin.controller.test.js
is located in 'app/admin' within the project directory.
Even after attempting to directly reference the files in my karma config file, I encountered an error message:
Module 'admin.module' 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.