本文介绍了在名称中注入带点的工厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Jasmine中使用angularjs模拟注入方法来注入名称中带点的服务。我试着添加字符串标识符,但inject方法似乎不支持这个。这是不可能的:

I need to use the angularjs mock inject method within Jasmine to inject a service with dots in the name. I tried to do add string identifiers but the inject method does not seem to support this. This is not possible:

beforeEach(inject(['$rootScope','MyApp.Factories.TestFactory',
    function ($rootScope, testFactory) {

    //doSomeThing

}]));

还有另一种处理方法吗?

Is there another way to handle this?

推荐答案

我没有对此进行过测试,但您可以自己从 $ injector 中获取它。这样的事情:

I haven't tested this, but you can probably get it from the $injector yourself. Something like this:

beforeEach(inject(function($rootScope,$injector) {
    var testFactory = $injector.get('MyApp.Factories.TestFactory');
    //doSomeThing

}));

这篇关于在名称中注入带点的工厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 12:19