TypeError:无法读取未定义的属性'prototype'和错误:声明位置

时间:2016-01-19 12:02:40

标签: angularjs unit-testing jasmine karma-runner

我正在尝试在angularjs中对我的控制器和服务进行单元测试,并且我遇到了以下错误。我是使用业力和茉莉花进行单元测试的新手,我不知道出了什么问题。我两天都在努力解决这些错误,但没有得到任何运气。谁能告诉我,这里有什么不对。

我的服务

define([], function () {
"user strict";

return [
    "$injector", "appService", "$log", "common.service",
    function ($injector, appService, $log, cs) {

        var webApi = appService.config.catererApiUrl;
        var webApiVersion = "V1/";
        var debtReportControllerName = "catererintegration/";

        var baseUrl = "./components/deptReport/";

        var service = null;

        function showDebtReport(catererId) {
            var dataToPost = {
                CatererId: catererId
            };

            var httpService = $injector.get("$http");
            var promise = httpService.post(webApi + debtReportControllerName + "GetIntegrationDebtReport", dataToPost);

            return promise.then(function (call) {

                service.debtReportDetails = call.data.Results;
                //console.log(service.debtReportDetails);
                //cs.$log.info(call.data.Results);
            });
        }


        function exportCatererDebtReport(debtReport) {
            var postData = {
                "DebtReports": [{ "CatererId": 10367 }]
            };

            var url = webApi + debtReportControllerName + 'ExportDebtReport?format=csv';
            var result = cs.downloadFile(url, postData);

            return result;
        }

        service = {
            debtReportDetails: null,
            showDebtReport: showDebtReport,
            exportCatererDebtReport: exportCatererDebtReport
        };

        return service;
    }
];});

我的规范文件

(function(define,describe){     'use strict';

var dependancies = [
    //"components/common/common.module",
    'components/debtReport/debtReport.service',
    'components/debtReport/debtReport.module'
];

define(dependancies, function (debtReportService, debtReportModule) { //commonModule,


    var catererBaseUrl = "http://localhost/catererintegration/";

    var $httpBackend, $rootScope, $q, $http, service, commonService, growl, usSpinnerService;

    describe("DebtReport Service Suite", function () {

        beforeEach(function () {
            module(debtReportModule); //commonModule,
        });

        beforeEach(function () {

            module(function ($provide) {
                $provide.service("appService");
                //$provide.service('debtReportService', debtReportService);
            });

            inject(["$httpBackend", "$rootScope", "$q", "debtReportService", "$http", "commonService", "usSpinnerService",
                function (_$httpBackend_, _$rootScope_, _$q_, _debtReportService_, _$http_, _commonService_, _usSpinnerService_) {
                $httpBackend = _$httpBackend_;
                $rootScope = _$rootScope_;
                $q = _$q_;
                debtReportService = _debtReportService_;
                $http = _$http_;
                commonService = _commonService_;
                usSpinnerService = _usSpinnerService_;
            }]);

            $httpBackend.whenPOST(catererBaseUrl + 'GetIntegrationDebtReport').respond(200, { CatererId: catererId });
            //$httpBackend.whenPOST(catererBaseUrl + 'GetIntegrationColourChoice').respond(200, {});

            spyOn(usSpinnerService, 'spin').and.callThrough();
            spyOn(usSpinnerService, 'stop').and.callThrough();
        });

        afterEach(function () {
            $httpBackend.verifyNoOutstandingExpectation();
            $httpBackend.verifyNoOutstandingRequest();
        });

        describe("DebtReport Service", function () {

            it("should be defined", function () {
                expect(debtReportService).toBeDefined();
            });

            it("showDebtReport should be defined", function () {
                expect(debtReportService.showDebtReport).toBeDefined();
            });

            it("exportCatererDebtReport should be defined", function () {
                expect(debtReportService.exportCatererDebtReport).toBeDefined();
            });
        });

    });

});})(define, describe);

运行测试时遇到的错误

Chrome 47.0.2526 (Windows 8.1 0.0.0) DebtReport Service Suite DebtReport Service should be defined FAILED
        TypeError: Cannot read property 'prototype' of undefined
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4480:82)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at Object.enforcedReturnValue [as $get] (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4325:37)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4290:37
            at getService (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4432:39)
            at invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4464:13)
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4481:27)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
        Error: Declaration Location
            at window.inject.angular.mock.inject (https://dvpp2aint.parentpay.com/resources/static/libs/angular-mocks/angular-mocks.js:2397:25)
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:73:5)
        TypeError: Cannot read property 'verifyNoOutstandingExpectation' of undefined
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:92:17)
Chrome 47.0.2526 (Windows 8.1 0.0.0) DebtReport Service Suite DebtReport Service should be defined FAILED
        TypeError: Cannot read property 'prototype' of undefined
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4480:82)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at Object.enforcedReturnValue [as $get] (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4325:37)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4290:37
            at getService (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4432:39)
            at invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4464:13)
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4481:27)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
        Error: Declaration Location
            at window.inject.angular.mock.inject (https://dvpp2aint.parentpay.com/resources/static/libs/angular-mocks/angular-mocks.js:2397:25)
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:73:5)
        TypeError: Cannot read property 'verifyNoOutstandingExpectation' of undefined
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:92:17)
Chrome 47.0.2526 (Windows 8.1 0.0.0) DebtReport Service Suite DebtReport Service showDebtReport should be defined FAILED
        TypeError: Cannot read property 'prototype' of undefined
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4480:82)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at Object.enforcedReturnValue [as $get] (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4325:37)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4290:37
            at getService (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4432:39)
            at invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4464:13)
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4481:27)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
        Error: Declaration Location
            at window.inject.angular.mock.inject (https://dvpp2aint.parentpay.com/resources/static/libs/angular-mocks/angular-mocks.js:2397:25)
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:73:5)
        Expected undefined to be defined.
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:103:53)
        TypeError: Cannot read property 'verifyNoOutstandingExpectation' of undefined
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:92:17)
Chrome 47.0.2526 (Windows 8.1 0.0.0) DebtReport Service Suite DebtReport Service showDebtReport should be defined FAILED
        TypeError: Cannot read property 'prototype' of undefined
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4480:82)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at Object.enforcedReturnValue [as $get] (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4325:37)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4290:37
            at getService (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4432:39)
            at invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4464:13)
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4481:27)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
        Error: Declaration Location
            at window.inject.angular.mock.inject (https://dvpp2aint.parentpay.com/resources/static/libs/angular-mocks/angular-mocks.js:2397:25)
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:73:5)
        Expected undefined to be defined.
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:103:53)
        TypeError: Cannot read property 'verifyNoOutstandingExpectation' of undefined
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:92:17)
Chrome 47.0.2526 (Windows 8.1 0.0.0) DebtReport Service Suite DebtReport Service exportCatererDebtReport should be defined FAILED
        TypeError: Cannot read property 'prototype' of undefined
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4480:82)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at Object.enforcedReturnValue [as $get] (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4325:37)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4290:37
            at getService (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4432:39)
            at invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4464:13)
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4481:27)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
        Error: Declaration Location
            at window.inject.angular.mock.inject (https://dvpp2aint.parentpay.com/resources/static/libs/angular-mocks/angular-mocks.js:2397:25)
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:73:5)
        Expected undefined to be defined.
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:107:62)
        TypeError: Cannot read property 'verifyNoOutstandingExpectation' of undefined
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:92:17)
Chrome 47.0.2526 (Windows 8.1 0.0.0) DebtReport Service Suite DebtReport Service exportCatererDebtReport should be defined FAILED
        TypeError: Cannot read property 'prototype' of undefined
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4480:82)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at Object.enforcedReturnValue [as $get] (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4325:37)
            at Object.invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4473:17)
            at https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4290:37
            at getService (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4432:39)
            at invoke (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4464:13)
            at Object.instantiate (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4481:27)
            at Object.<anonymous> (https://dvpp2aint.parentpay.com/resources/static/libs/angular/angular.js:4341:24)
        Error: Declaration Location
            at window.inject.angular.mock.inject (https://dvpp2aint.parentpay.com/resources/static/libs/angular-mocks/angular-mocks.js:2397:25)
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:73:5)
        Expected undefined to be defined.
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:107:62)
        TypeError: Cannot read property 'verifyNoOutstandingExpectation' of undefined
            at Object.<anonymous> (C:/Files/ParentPay2/trunk/Apps.UI/Caterer/src/components/debtReport/debtReport.service.spec.js:92:17)
Chrome 47.0.2526 (Windows 8.1 0.0.0): Executed 3 of 3 (3 FAILED) ERROR (0.074 secs / 0.034 secs)

0 个答案:

没有答案