Karma Jasmine: Completed 0 of 0 Error
I get into Angular Testing with Karma and Jasmine. After running karma init
and writing my first home controller test, I keep getting Executed 0 of 0 ERROR
. There seems to be no.
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'public/assets/libs/angular/angular.min.js',
'bower_components/angular-mocks/angular-mocks.js',
'public/app/app.module.js',
'public/app/app.config.js',
'public/app/**/*.js',
'test/unit/**/*.spec.js'
],
exclude: [
],
preprocessors: {
},
reporters: ['progress'],
port: 3030,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
}); //config.set
} //module.export
Test (fixed)
describe('HomeController', function() {
//Inject 'app' module into this spec.
beforeEach(module('app'));
//Inject instance of Scope.
var homeController;
beforeEach(inject(function($rootScope, $controller) {
//create a new scope
scope = $rootScope.$new();
//create new controller, using the newly created scope
HomeController = $controller('HomeController', {
$scope: scope
});
}));
//Set expectations
it('the message should say Hello World', function(HomeController) {
expect(scope.message).toBe('Hello World');
});
});
And HomeController:
(function() {
'use strict';
angular
.module('app')
.controller('HomeController', HomeController);
HomeController.$inject = ['$scope', '$log'];
function HomeController($scope, $log) {
/*jshint validthis: true*/
var vm = this;
vm.message = 'Hello World';
} //HomeController()
})(); //Controller
Thanks for the help.
source to share
For all those who also face the "Done 0 of 0 ERROR" problem:
Here's how best to debug this error, as the log message on the command line may be truncated or not useful enough:
On an instance of Karma browser (like Chrome), set a breakpoint at karma.js
in the following function:
this.error = function (msg, url, line) {
Since the string representation msg
that will be pushed to the command line log is not very useful, parse it here.
source to share