title: Testing whether $httpProvider.interceptors.push() have been called with jasmine in Angular
body: <p>I have found many articles here how to test Angular's config phase and I was able to create my tests against <a href="https://github.com/mgonto/restangular" rel="nofollow">restangular</a> and <a href="https://github.com/grevory/angular-local-storage" rel="nofollow">LocalStorageModule</a> module configuration. The only one I cannot solve yet is checking whether the interceptor was added or not. I do not need to test the service because it is a 3rd party stuff, I consider it is already tested - hopefully.</p>
  
  <p>The question is that, how can I spy on $httpProvider.interceptors.push method which is called in configuration phase?</p>
  
  <p>Thanks for any help in advance!</p>
  
  <p>Here is my code:</p>
  
  <pre class="lang-js prettyprint-override"><code>(function () {
      'use strict';
  
      angular.module('myapp', [
              // Angular modules
              'ngAnimate',
              'ngRoute',
  
              // Custom modules
              'myapp.layout',
  
              // 3rd Party Modules
              'LocalStorageModule',
              'http-auth-interceptor',
              'restangular'
      ])
      .config(function (RestangularProvider) {
  
          RestangularProvider.setBaseUrl('http://.../services/webapi/');
  
      })
      .config(function (localStorageServiceProvider) {
  
          localStorageServiceProvider.setPrefix('myapp');
  
      })
      .config(function($httpProvider) {
  
          $httpProvider.interceptors.push('authInterceptorFactory');
  
      });
  })();
  
  
  'use strict';
  
  describe('myapp configuration', function() {
  
      var RestangularProvider,
          localStorageServiceProvider,
          $httpProvider;
  
      //modules
      beforeEach(function () {
  
          angular.module('myapp.layout', []);
          angular.module('http-auth-interceptor', []);
  
      });
  
  
      //providers
      beforeEach(function () {
  
          module('restangular', function(_RestangularProvider_) {
  
              RestangularProvider = _RestangularProvider_;
              spyOn(RestangularProvider, 'setBaseUrl').and.callThrough();
          });
  
          module('LocalStorageModule', function (_localStorageServiceProvider_) {
  
              localStorageServiceProvider = _localStorageServiceProvider_;
              spyOn(localStorageServiceProvider, 'setPrefix').and.callThrough();
  
          });
  
          module('myapp', function(_$httpProvider_) {
  
              $httpProvider = _$httpProvider_;
              spyOn($httpProvider.interceptors, 'push').and.callThrough();
  
          });
  
          //module('myapp');
  
          inject();
  
      });
  
      describe('Restangular configuration', function() {
  
          it('setBaseUrl is set up', function() {
  
              expect(RestangularProvider.setBaseUrl).toHaveBeenCalled();
  
          });
  
      });
  
      describe('localStorage configuration', function() {
  
          it('setPrefix is set up', function () {
  
              expect(localStorageServiceProvider.setPrefix).toHaveBeenCalled();
  
          });
  
      });
  
      describe('$httpProvider configuration', function() {
  
          it('an interceptor is added', function() {
  
              expect($httpProvider.interceptors.push).toHaveBeenCalled();
  
          });
  
      });
  
  });
  </code></pre>