3

I'm actually stuck since few hours, my boss wants me to proceed to unit testing on the functionalities i coded last week, when I do my karma start karma.conf.js it gives me the following issue :

"message": "An error was thrown in afterAll\nUncaught ReferenceError: angular is not defined",

my files structure :

webapp
    -www
        -services
            api.service.js
    -test
        test.test.js
    karma.conf.js

essential of karma.conf.js :

module.exports = function(config) {
  config.set({
  files: [
    'www/js/services/api.service.js',
    'test/**/*.test.js'
  ],
})
}

I think Karma doesn't find my api.service.js but i don't know why, the angularjs code actually work in the webapp.

content of my test.test.js :

(function() {
'use strict';

   describe('apiService', function() {

     it('should return an array of object', function() {
     var artist = typeof getArtist(118680); // MGMT Artist
     console.log(artist);
     expect(artist).toEqual('array');
     });
   });
})();

getArtist is the function I need to test situated in api.service.js.

Thank you,

Paul.

1 Answer 1

5

Karma needs the angular file to test angularJS code. You need to include it in the files array in the karma configuration.

module.exports = function(config) {
  config.set({
  files: [
    'path-to-angular.js',
    'www/js/services/api.service.js',
    'test/**/*.test.js'
  ],
 })
} 
Sign up to request clarification or add additional context in comments.

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.