意外请求获取angularjs中的scripts / modules / packages / views / desktop / index.html

时间:2014-03-21 19:20:13

标签: angularjs unit-testing

我在angularjs单元测试控制器中获取了脚本/ modules / packages / views / desktop / index.html的意外请求

   "use strict";
    describe('ST Packages', function () {
        beforeEach(function () {
            module('st.packages');
        });
        var packagesViewCtrl, $timeout, $q, deferred;
        $timeout = function (a) {
            a();
        };
        describe('packagesViewCtrl', function () {

            var $scope , Packages, MessageService, $filter, $modal, Util, $httpBackend ;

            beforeEach(function () {
                Packages = {
                    getPackage: function () {
                        return {};
                    },
                    getPackageItems:function(){
                        deferred = $q.defer();
                        return deferred.promise;
                    },
                    getPackageSubscriptions:function(){
                        deferred = $q.defer();
                        return deferred.promise;
                    }/*,
                    changePackageStatus:function(){
                        deferred = $q.defer();
                        return deferred.promise;
                    }*/,
                    deletePackage:function(){
                        deferred = $q.defer();
                        return deferred.promise;
                    }
                };

                $filter = function() {
                    return function(){};
                };

                MessageService = {
                    setSuccess : function() {},
                    setError : function() {}
                };
                $modal = function() {
                    return {};
                };

                spyOn(MessageService, 'setSuccess');
                spyOn(MessageService, 'setError');

                inject(function ($controller, $rootScope,_$q_,$injector) {
                    $scope = $rootScope.$new();
                    $q = _$q_;
                    $httpBackend=$injector.get('$httpBackend');
                    packagesViewCtrl = $controller('packagesViewCtrl', {
                        $scope: $scope,
                        $timeout: $timeout,
                        Packages: Packages,
                        $q: $q,
                        $filter: $filter,
                        $modal: $modal,
                        $httpBackend:$httpBackend,
                        Util: Util,
                        MessageService: MessageService
                    });
                });


            });

            it("should get package detail", function () {
                $scope.package={};
                $scope.loadPackage();
                expect($scope.package).toEqual({});
            });

            /*it("should get package items", function () {
                //$scope.packageItems=[{name:"packitem1"},{name:"packitem2"}]
                $scope.getPackageItems();

                deferred.resolve([
                    {Id:101, Name: 'item1'},
                    {Id:102, Name: 'item2'}]);
                $scope.$digest();
                expect($scope.packageItems.length).toBe(2);
            });

            it("should change package status", function () {

                $scope.changePackageStatus();
                deferred.resolve("success");
                $scope.$digest();
                expect(MessageService.setSuccess).toHaveBeenCalled();

                $scope.changePackageStatus();
                deferred.resolve("rejected");
                $scope.$digest();
                expect(MessageService.setError).toHaveBeenCalled();
            });*/
            it("should delete package", function () {

                $scope.deletePackage();
                deferred.resolve("success");
                $httpBackend.expectGET('scripts/modules/packages/views/desktop/index.html').respond(200);
                //$scope.$digest();
                expect(MessageService.setSuccess).toHaveBeenCalled();
            });


        });

    });

0 个答案:

没有答案