jeudi 26 mai 2016

karma trouble with angular constant

I had working tests before a merge of 2 branches. The new branch brought along an angular constant which I believe broke all the tests. I have an angular constant like so

...
return $http.get(ENV+'/api/url').then(function (response) {
                appName.constant("userinfo", response.data);
                userID = response.data.user.id;
            }, function(errorResponse) {...

and my test controller set up like this

beforeEach(function() {
    module('appName');
    return inject(function($injector) {
      //nothing here yet
    });
  });

I was able to shorten the amount of errors by creating this stub for the constant that my tests would use

angular.module('appName').constant('userinfo', {
  user: {
    id: 0
  }
});

window.ENVApp = '/ng-app'

And I am running into this error

Error: [$injector:unpr] http://ift.tt/1ZsJvtS$injector/unpr?p0=httpInterceptorProvider%20%3C-%20httpInterceptor%20%3C-%20%24http%20%3C-%20%24templateRequest%20%3C-%20%24compile%20%3C-%20ModalService%20%3C-%20taOptions

The files are loaded into karma.conf. Any ideas how to get around this error? My tests wont run because of this issue.

Aucun commentaire:

Enregistrer un commentaire