Angular undefined error while testing karma jasmin
I'm new to testing using Karma-jasmine to run a test, but I am getting an error.
My karma.conf.js
files: [
'test/*Spec.js',
'app/js/*.js'
],
This error is displayed on the command line
Chrome 39.0.2171 (Windows 7) ERROR
Uncaught TypeError: Cannot read property 'module' of undefined
at D:/Test_Samples/WebContent/MyTest/app/js/angular-route.js:24
Firefox 34.0.0 (Windows 7) ERROR
TypeError: angular is undefined
at D:/Test_Samples/WebContent/MyTest/app/js/angular-route.js:24
IE 8.0.0 (Windows 7) ERROR
'undefined' is null or not an object
at D:/Test_Samples/WebContent/MyTest/app/js/angular-route.js:24
angular-route.js: 24
/* global -ngRouteModule */
var ngRouteModule = angular.module('ngRoute', ['ng']).provider('$route', $RouteProvider),
$routeMinErr = angular.$$minErr('ngRoute');
source to share
You need to import angular and angular files before testing. This is an example of the configuration I'm using:
files: [
{pattern: 'src/main/webapp/static/libs/jquery/dist/jquery.js', watch: false},
{pattern: 'src/main/webapp/static/libs/angular/angular.js', watch: false},
{pattern: 'src/main/webapp/static/libs/angular-resource/angular-resource.js', watch: false},
{pattern: 'src/main/webapp/static/libs/angular-mocks/angular-mocks.js', watch: false},
{pattern: 'src/main/webapp/static/libs/angular-ngkit/js/ngkit.js', watch: false},
'src/main/webapp/static/templates/angular/*.html',
'src/main/webapp/static/js/angular/**/*.js',
'src/test/js/spec/angular/*.js'
],
It is best to avoid looking at libraries ( watch: false
) as these files will not change during development!
It is also important to define the " basePath
" property , since all paths will be resolved using this root!
source to share
You need to reference your angular.js file before any other angular file. Be sure to check your config file for the config file you get when installing karma. See this web page for details. http://karma-runner.github.io/0.12/config/configuration-file.html
source to share