3

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');

2 Answers 2

6

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!

Sign up to request clarification or add additional context in comments.

Comments

0

You need to reference angular.js file before any other angular file. Make sure to check your config file against the config file that you get when you install karma. Refer to this webpage for details. http://karma-runner.github.io/0.12/config/configuration-file.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.