【发布时间】:2015-09-01 00:42:50
【问题描述】:
我试图在我的一个 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
// ...
})
})
当我$ protractor conf.js 时出现问题,我收到错误消息:
Error while running module script administrationServices: [$injector:nomod] http://errors.angularjs.org/1.3.4/$injector/nomod?p0=administrationServices
这就是我感到困惑的地方。每篇关于量角器的 addMockModule 的博客文章似乎都使用类似的语法。 AdministrationServices 中还有其他工厂服务,这些服务似乎被覆盖,因为这些服务(用户和组服务)不起作用,应用程序无法打开页面。
无论如何,如果有人看到了这一点并且可以帮助我朝着正确的方向前进,那将会有所帮助;我对模拟服务、量角器和 e2e 测试相当陌生。
【问题讨论】:
标签: angularjs protractor e2e-testing