Struggling to unit test Angular, was this module the best approach? As a development team we've recently started to transition from MVC to Angular. None of us have had prior experience with it so a lot of creating the new client was very much trial and error. I've been put in charge of sorting out unit tests however I'm finding it very difficult to unit test. 

In my experience if something is difficult to unit test it generally means some refactoring is in order. Problem is I do not have enough experience with Angular to say yay or nay on this. 

Main angular module:

angular.module('serviceApp', ['mgcrea.ngStrap', 'ngRoute', 'LocalStorageModule', 'account.module', 'admin.module', 'design-code-review.module', 'early-load-test.module', 'integration-load-test.module', 'production-validation.module', 'risk-modelling.module', 'unit-test-profiling.module','error.module'])
.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
        .when('/login', {
            templateUrl: '/views/account/login.html',
            controller: 'account.controller'
        })
         .when('/admin', {
             templateUrl: '/views/admin/project-admin.html',
             controller: 'admin.controller'
         })
        .when('/register', {
            templateUrl: '/views/account/register.html',
            controller: 'account.controller'
        })
        .otherwise('/login');
}])    
.config(function($httpProvider){
    $httpProvider.interceptors.push('authentication.interceptor')
})
.run(['authentication.service', function (authentication) {
    authentication.populateAuthentication();
}]);


Declared in other js files are factories and services for our serviceApp

Example factory class:

angular.module('serviceApp')
.factory('storage.factory', ['$http', 'applicationSettings', 'localStorageService', function ($http, applicationSettings, localStorageService) {

    var getItems = function () {
        return $http.get(applicationSettings.apiLocation + 'Items/GetAll').then(function (response) {
            localStorageService.set('items', response.data);
        },
        function (error) {
            console.log("Could not retrieve data.");
        });
    };

    return {
        getItems: getItems 
    };
}]);


Currently I'm having a lot of trouble trying to test these factories and services because of the sheer number of dependencies that serviceApp has. When looking for examples online I see that a lot of modules have only 1 or 2 dependencies which got me thinking whether the above is typical of an Angular application. Is having a lot of dependencies for a module like this ok in Angular? Or am I being a bit dense and need to get my unit testing in order?
Injecting the $injector service can help by facilitating the use of optional dependencies:

app.factory('templateRepository', [ '$injector', function($injector) {
  function lookupUrlFor(contentType) {
   // Do your translation here
  }

  return {
    getTemplate: function(contentType) {
      var templateCache = $injector.get('$templateCache');
      return templateCache.get(lookupUrlFor(contentType));
      }
    }
}])


That way the unit tests only needs to inject $injector and mocks can be avoided.

References


Optional Dependencies in Angular.js
Avoid circular dependencies with AngularJS Directives | endjin blog
ngMock / $httpBackend