karma.config.js:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'node_modules/angular/angular.min.js',
'node_modules/angular-mocks/angular-mocks.js',
'node_modules/angular-translate/dist/angular-translate.min.js',
'browser/javascripts/*.js',
'browser/tests/*.spec.js'
],
exclude: [],
preprocessors: {},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
};
home.spec.js:
describe('Home Controller', function() {
beforeEach(
module('pascalprecht.translate'),
module('tradeshiftApp')
);
var $controller;
beforeEach(inject(function(_$controller_){
$controller = _$controller_;
}));
it('should exist', function(){
controller = $controller('HomeController', {
$scope: {}
});
expect(controller).not.toBe(undefined);
})
});
I am utilizing karma-jasmine
and encountering an issue. When I try to mock my controller defined in the app.js
file, as shown below:
var app = angular.module('tradeshiftApp', ['pascalprecht.translate']);
An error is thrown stating that HomeController
is not recognized as a function. Despite ensuring all dependencies are correctly set up, this unexpected behavior occurs. Any insights or suggestions would be greatly appreciated.
Note: A successful injection of $rootScope
using $rootScope.$new()
has been attempted.