我目前正在开发基于Cordova(http://cordova.apache.org)的应用程序,目前部署在iOS上。
我已经开始使用jasmine编写一些单元测试,就像我以前用AngularJS开发浏览器应用程序时那样(使用Jasmine)。
var custom_matchers = {
toBeAFunction: function () {
var actual = this.actual;
var notText = this.isNot ? " not" : "";
this.message = function() {
return "Expected " + actual.constructor.name + notText + " to be a function";
};
return angular.isFunction(actual);
}
}
describe("Test using aboutUsCtrl", function () {
var $controller, $scope;
beforeEach(function () {
module("app");
inject(function ($rootScope, _$controller_) {
$scope = $rootScope.$new();
$controller = _$controller_;
});
this.addMatchers(custom_matchers);
})
describe(", creating a controller", function () {
var controller;
beforeEach(function () {
controller = $controller("aboutUsCtrl", {$scope: $scope});
});
it("should have a 'deleteAccount' function", function () {
expect($scope.deleteAccount).toBeDefined();
expect($scope.deleteAccount).toBeAFunction();
});
it("should have a 'goNext' function", function () {
expect($scope.goNext).toBeDefined();
expect($scope.goNext).toBeAFunction();
})
});
})
当我执行这段代码时,我收到一个由Cordova抛出的错误:Function required as first argument!
。一项快速的研究让我意识到Cordova被告知订阅一系列函数(Channel.subscribe
)而不仅仅是一个函数。请注意,如果我完全删除每个测试,则不会发生此错误。
这是我做错了什么的结果吗?
在你问之前,这是我的业力配置文件:http://pastebin.com/JzMGgHPn
答案 0 :(得分:1)
我的问题非常复杂,因为我的案例单元测试并不是很多。 基本上,我在我的Karma跑步者中包括cordova.js,因为我的一个js文件需要它。我发现这个js文件(PushNotification.js)并不需要包含在这里,解决了我的问题。