在单元测试Angular 1.2中发现Bower依赖性,但在Angular 1.5中找不到 [英] Bower dependency found in unit test Angular 1.2, but cannot be found Angular 1.5

查看:87
本文介绍了在单元测试Angular 1.2中发现Bower依赖性,但在Angular 1.5中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Angular从1.2.28升级到1.5.5时遇到问题.代码本身运行起来很吸引人,但是我的测试由于以下消息而开始失败.

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.

未知提供者:storeProvider<-store<-translateStorage

Unknown provider: storeProvider <- store <- translateStorage

我使用"a0-angular-storage":"0.0.15"作为storeProvider,它通过

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(){...}

angular.module('angular-storage.store', ['angular-storage.internalStore']) .provider('store', function() { ...}

删除了所有代码,并引用了我可以重现该问题的github存储库. https://github.com/debrutal/js-hazzle

removed all the code and referred to a github repo where i could reproduce the problem. https://github.com/debrutal/js-hazzle

如果我使用1.2.28运行test(gulp测试),angular能够将存储(语言始终有效,因为它只是应用程序中的已定义变量)注入我的测试中. 1.5.5无法这样做. 在业力中,我要在测试之前加载应用程序,我要在应用程序之前加载Bower依赖项.

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?

推荐答案

好的,我找到了原因.我的依存关系组织得不好.换句话说,我在应用程序依赖项本身中而不是在模块中拥有所有外部依赖项,而这确实需要它.

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.

我的应用具有依赖项: angular.module('app',['a0-angular-storage','vt.utils'])angular.module('vt.utils',[]). 对"a0-angular-storage"的依赖关系应该是可传递的,因为只有vt.utils使用a0-angular-storage的服务.模块"app"本身不直接依赖于该模块的任何服务.

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.

当我执行beforeEach('vt.utils');时,我只是加载要测试的模块而没有对该模块的依赖关系,因此karma无法从该模块中找到服务,因为该服务未在测试中加载.

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.

现在也许是: 我猜想可能是一个原因,为什么业力无法检索已加载的模块,因为从Angle 1.3开始,测试处于隔离环境中.

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?

这篇关于在单元测试Angular 1.2中发现Bower依赖性,但在Angular 1.5中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆