Skip to content

Instantly share code, notes, and snippets.

Created December 22, 2013 05:36
Show Gist options
  • Save anonymous/8078797 to your computer and use it in GitHub Desktop.
Save anonymous/8078797 to your computer and use it in GitHub Desktop.
My project using Angular and Karma, following this tutorial: https://coderwall.com/p/xz-qcg Not sure why I am getting the error (see Error.md).
// Karma configuration
// Generated on Sun Dec 22 2013 16:22:57 GMT+1100 (EST)
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '..',
// frameworks to use
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'public/app/lib/angular/angular.min.js',
'test/lib/angular/angular-mocks.js',
'public/app/*.js',
'test/unit/*Spec.js',
'test/e2e/*Spec.js',
'test/e2e/*.js'
],
// list of files to exclude
exclude: [
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['PhantomJS'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};

###Error from karma start configs/karma.cf.js INFO [PhantomJS 1.9.2 (Linux)]: Connected on socket PK-IbFeI1qpFq0fix6WI PhantomJS 1.9.2 (Linux) IndexController should add name parameter to scope FAILED Error: [$injector:modulerr] http://errors.angularjs.org/1.2.6/$injector/modulerr?p0=myapp.controllers&p1=Error%3A%20%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.2.6%2F%24injector%2Fnomod%3Fp0%3Dmyapp.controllers%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9877%2Fbase%2Fpublic%2Fapp%2Flib%2Fangular%2Fangular.min.js%3F1387689655000%3A20%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9877%2Fbase%2Fpublic%2Fapp%2Flib%2Fangular%2Fangular.min.js%3F1387689655000%3A21%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9877%2Fbase%2Fpublic%2Fapp%2Flib%2Fangular%2Fangular.min.js%3F1387689655000%3A29 at /home/Projects/abbrevi8-karma-tests/public/app/lib/angular/angular.min.js:29 TypeError: 'undefined' is not an object (evaluating 'scope.name') at /home/Projects/abbrevi8-karma-tests/test/unit/controllerSpec.js:19 PhantomJS 1.9.2 (Linux): Executed 1 of 1 (1 FAILED) ERROR (0.178 secs / 0.006 secs)

var myApp = angular.module('myApp', []);
myApp.controller('IndexController', function ($scope) {
$scope.name = 'bob';
}
);
use strict';
describe('IndexController', function() {
//initialise module
beforeEach(module('myapp.controllers'));
//params initialised in scope for tests
var ctrl, scope;
beforeEach(inject(function($controller) {
//get controller from $controller provider
scope = {};
ctrl = $controller('IndexController', {
$scope: scope
});
}));
it ('should add name parameter to scope', function() {
expect(scope.name).toBeDefined();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment