问题
I have an issue while upgrading Angular from 1.2.28 to 1.5.5. The code itself runs like a charm, but my tests began to fail with the following message.
Unknown provider: storeProvider <- store <- translateStorage
I use "a0-angular-storage": "0.0.15" as a storeProvider which provides 'store' via
angular.module('angular-storage.store', ['angular-storage.internalStore']) .provider('store', function() { ...}
[EDIT:] removed all the code and referred to a github repo where i could reproduce the problem. https://github.com/debrutal/js-hazzle
If i run the test(gulp test) with 1.2.28 angular is capable to inject store (language allways works, as it is just a defined variable within the application) into my tests. 1.5.5 is not able to do so. In karma i am loading the application before the tests and i am loading the bower dependencies before the application.
What am i missing? And why is it this way?
回答1:
Ok, i found the reason. My dependencies were not really well organized. In other words, i had all external dependcies within the application dependency itself and not in the module, that really needs it.
My app has the dependency:
angular.module('app',['a0-angular-storage','vt.utils'])
and angular.module('vt.utils',[])
.
The dependency to 'a0-angular-storage' should be transitive, as only vt.utils uses a service from a0-angular-storage. The module 'app' itself has no direct dependency to any service of that module.
When i do beforeEach('vt.utils');
i just load the module i want to test without the dependency to that module, so karma is not able to find the service from that module, as it is not loaded within the test.
Now comes the maybe: I GUESS that this could be a reason, why karma is not able to retrieve the loaded modules, as from angular 1.3 the test are in an isolatet environment.
I've spent a lot of time for this, can someone confirm this to me? Or is it something else i missed?
来源:https://stackoverflow.com/questions/37294411/bower-dependency-found-in-unit-test-angular-1-2-but-cannot-be-found-angular-1-5