Search code examples
angularjsjasmineprotractorangularjs-ngmock

Where to declare ngMock module


I've just started wading through unit and end-to-end testing for an angular app.

I'm confused as to where I should declare the ngMock and ngMocke2e modules. My bower.json file has the reference to ngMock, and the index.html file is pointing to angular-mocks.js script.

However, when I declare ngMock in the dependencies of my app.js, the application won't load. Furthermore, there are no errors displayed in the console.

I need to use these modules for testing, but it seems counter-intuitive to inject them into the app from app.js.


Solution

  • You don't need to add angular-mocks to your main app.js You need to inject angular-mocks into your karma conf, which is the only place that needs it.

    For example:

    module.exports = function(config) {
      'use strict';
    
      config.set({
    
        files: [
          'bower_components/angular/angular.js',
          'bower_components/angular-resource/angular-resource.js',
          ...
          'bower_components/angular-mocks/angular-mocks.js'
          ...
    
        ]
    
      });
    };