Bower dependency found in unit test Angular 1.2, but cannot be found Angular 1.5

柔情痞子 提交于 2019-12-12 22:24:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!