I am new to Testing using Karma-jasmine to run the test but getting error.
My karma.conf.js
files: [
'test/*Spec.js',
'app/js/*.js'
],
This error is Showing in 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');
You have to import angular and angular-stuff before your tests. This is an example of 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's a best practice to avoid the watching of the libraries (watch: false), since those files won't change during the development!
It's also important to define the "basePath" property, since all the paths will be resolved using that root!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With