科尔多瓦公司;AngularJS单元测试

科尔多瓦公司;AngularJS单元测试,angularjs,unit-testing,cordova,jasmine,karma-runner,Angularjs,Unit Testing,Cordova,Jasmine,Karma Runner,我目前正在开发一个基于Cordova()的应用程序,目前部署在iOS上 我已经开始使用jasmine编写一些单元测试,就像我使用AngularJS(使用jasmine)开发浏览器应用程序时一样 当我执行这段代码时,Cordova抛出了一个错误:Function required作为第一个参数。快速研究使我意识到Cordova被告知订阅一系列函数(Channel.subscribe),而不是只订阅一个函数。请注意,如果我完全删除每个测试,则不会发生此错误 这是我做错事的结果吗 在您提问之前,这里是

我目前正在开发一个基于Cordova()的应用程序,目前部署在iOS上

我已经开始使用jasmine编写一些单元测试,就像我使用AngularJS(使用jasmine)开发浏览器应用程序时一样

当我执行这段代码时,Cordova抛出了一个错误:
Function required作为第一个参数。快速研究使我意识到Cordova被告知订阅一系列函数(
Channel.subscribe
),而不是只订阅一个函数。请注意,如果我完全删除每个测试,则不会发生此错误

这是我做错事的结果吗


在您提问之前,这里是我的karma配置文件:

我的问题非常复杂,因为我的案例中没有太多关于单元测试的内容。 基本上,我在Karma runner中包含了cordova.js,因为我的一个js文件需要它。我发现这个js文件(PushNotification.js)不需要包含在这里,解决了我的问题

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();
        })

    });

})