mercredi 30 mars 2016

Why do Angular unit tests load $route?

After updating to Angular 1.5.3 (from 1.4.9) all my unit tests have started failing, where they worked before.

The error is as follows:

Error: [$injector:unpr] Unknown provider: 
       AuthenticationHttpInterceptorProvider
         <- AuthenticationHttpInterceptor
           <- $http
             <- $templateRequest
               <- $route

It is expected that the AuthenticationHttpInterceptorProvider is not known at this point, because it is part of a different module which is not unit tested here. If I provide a mock for this interceptor, I get the error that $httpBackend wasn't expecting a GET request for the defined default route.

My question is: Why does $route get loaded in the first place, and how can I prevent it? I'm not unit testing any routes and make no changes to $route after the .config stage in the app where routes are defined. I would expect to never receive any requests for the templateUrls of the views of routes.

I've not been able to find anything in the Angular Changelog that would make me expect a different behaviour with the newer version.

Aucun commentaire:

Enregistrer un commentaire