Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不可用模块错误:使用量角器覆盖AngularJS工厂以进行E2E测试_Angularjs_Protractor_E2e Testing - Fatal编程技术网

不可用模块错误:使用量角器覆盖AngularJS工厂以进行E2E测试

不可用模块错误:使用量角器覆盖AngularJS工厂以进行E2E测试,angularjs,protractor,e2e-testing,Angularjs,Protractor,E2e Testing,我试图在我的angularjs模块中模拟一个工厂。完整的angularjs应用程序是 angular.module('administration', ['administrationServices']) 依赖关系: var module = angular.module('administrationServices') 包含工厂服务: module.factory('Example', [function(){ return{ list:function(){

我试图在我的angularjs模块中模拟一个工厂。完整的angularjs应用程序是

angular.module('administration', ['administrationServices'])
依赖关系:

var module = angular.module('administrationServices')
包含工厂服务:

module.factory('Example', [function(){
    return{
        list:function(){
            return ['This is real']
        }
    }
}])
这是我在量角器e2e测试中试图覆盖的服务。实际测试如下所示:

describe('Example page', function(){
    beforeEach(function() {
        var mock = function(){

            // get the module and provide the mock
            var module = angular.module('administrationServices').config(['$provide', function($provide){
                $provide.factory('Example',[function(){
                    return {
                        list: function(){
                            return ['This is a Mock Test'] 
                        }
                    }
                }])
            }])
        }

        // override the mock service
        browser.addMockModule('administrationServices', mock)

    })

    it('should go to the page and see mock text', function() {
        // code that goes to page and checks if the service works
        // ...
    })

})
我遇到的问题发生在我
$dragrator conf.js
时,我得到错误:

 Error while running module script administrationServices: [$injector:nomod] http://errors.angularjs.org/1.3.4/$injector/nomod?p0=administrationServices
这就是我困惑的地方。每一篇关于Gragrator的addMockModule的博客文章似乎都使用了类似的语法。administrationServices中还有其他factory服务,这些服务似乎被覆盖,因为这些服务(用户和组服务)不工作,应用程序无法打开页面


不管怎么说,如果有人看到了这一点,并能帮助我朝着正确的方向前进,那会有所帮助;我对模拟服务、量角器和e2e测试相当陌生

我认为问题在于模拟函数没有返回任何内容。它不在功能范围之外共享新模块

var mock = function(){

        // get the module and provide the mock
        return angular.module('administrationServices').config(['$provide', function($provide){
            $provide.factory('Example',[function(){
                return {
                    list: function(){
                        return ['This is a Mock Test'];
                    }
                }
            }])
        }])
    };

    // override the mock service
    browser.addMockModule('administrationServices', mock)
只要让它返回新模块,它就应该可以了