【发布时间】:2016-02-12 19:03:21
【问题描述】:
我有一个功能完善的应用程序,运行 Electron 和 Protractor 来进行测试。我能够对 DOM 元素进行测试,但我无法找到一种方法来测试我在控制器中拥有的功能。我收到此错误消息
失败:
1) app-controller.js 遇到声明异常
留言:
ReferenceError:未定义窗口
堆栈跟踪:
ReferenceError:未定义窗口
在对象。 (/home/yann/workspace/hacker-keyboard/node_modules/angular/angular.js:28902:4)
在需要 (module.js:384:17)
在对象。 (/home/yann/workspace/hacker-keyboard/node_modules/angular/index.js:1:63)
我查看了很多帖子,AngularJS documentation,但我还没有找到解决问题的方法。
以下是我用于测试的文件:
app.js
var app = angular.module('app', [
'appController'
]);
var controllerModule = angular.module('appController', []);
app-controller.js
controllerModule.controller('appController', ['$scope',
'$timeout',
'$window',
'$interval',
'$filter',
function ($scope, $timeout, $window, $interval, $filter){
/* controller code here */
}]);
conf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['test-spec.js'],
capabilities: {
browserName: "chrome",
chromeOptions: {
binary: "./dist/myApp-linux-x64/myApp"
}
},
onPrepare: function () {
browser.resetUrl = "file://";
}
};
test-spec.js
describe('app-controller.js', function () {
require('angular');
require('angular-mocks');
var scope, controller;
beforeEach(function () {
module('app');
});
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
controller = $controller("appController", {
$scope: scope
});
}));
it('should return empty string',
function () {
var result = scope.fooFunction(12, 'blue');
expect(result).toEqual("");
});
});
你们知道我错过/误解了什么吗?
编辑
因为我不在 Angular 文件中,所以我无权访问 window 对象。 angular 和 angular-mocks 的要求导致错误,因为它无法访问 window 对象。有谁知道如何将它链接到我的 test-spec.js 文件中?
【问题讨论】:
标签: angularjs unit-testing protractor electron