當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript angular.mock類代碼示例

本文整理匯總了TypeScript中angular.mock的典型用法代碼示例。如果您正苦於以下問題:TypeScript mock類的具體用法?TypeScript mock怎麽用?TypeScript mock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了mock類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: beforeEach

 beforeEach(() => {
   mock.module(HELP_FIELD_COMPONENT, ($provide: IProvideService) => {
     $provide.constant('helpContents', { 'aws.serverGroup.stack': 'expected stack help' });
   });
 });
開發者ID:emjburns,項目名稱:deck,代碼行數:5,代碼來源:helpField.component.spec.ts

示例2: describe

describe("PageEditorService", () => {
    let service: PageEditorService, dataService: DataService;

    beforeEach(() => {
        angular.mock.module(PAGE_EDITOR_MODULE);
        angular.mock.module(DATA_MODULE);
    });

    beforeEach(angular.mock.inject($injector => {
        service = $injector.get("PageEditorService");
        dataService = $injector.get("DataService");

        spyOn(dataService, "getData");
    }));

    it("should get data when getPages is called for editor page", () => {
        service.getPages();

        expect(dataService.getData).toHaveBeenCalledWith({
            webservice: "api/pages?includeHtml=N",
            type: "GET"
        });
    });

    it("should get updatable pages when getUpdatablePages is called", () => {
        service.getUpdatablePages();

        expect(dataService.getData).toHaveBeenCalledWith({
            webservice: "api/pages?isUpdatable=true",
            type: "GET"
        });
    });

    it("should post all updatable pages when postAllPagesFromRepo is called", () => {
        service.postAllPagesFromRepo();

        expect(dataService.getData).toHaveBeenCalledWith({
            webservice: "api/pages",
            type: "POST"
        });
    });

    it("should post single page when postPageFromRepo is called", () => {
        service.postPageFromRepo("12steps");

        expect(dataService.getData).toHaveBeenCalledWith({
            webservice: "api/pages/12steps",
            type: "POST"
        });
    });

    it("should get data when getMeetings is called for editor page", () => {
        service.getPage("12steps", 2);

        expect(dataService.getData).toHaveBeenCalledWith({
            webservice: "api/pages?pageName=12steps&revision=2",
            type: "GET"
        });
    });

    it("should post single page when postPage is called", () => {
        service.postPage("read-andallo", 3, {
            PageTitle: "...And All Other Mind Altering Substances",
            PageContent: "<div>new content</div>",
            Status: "ACTIVE",
            ContentType: "R",
            ImageFilename: "PAMPHLETS_All_Other"
        });

        expect(dataService.getData).toHaveBeenCalledWith({
            webservice: "api/pages/read-andallo/3",
            type: "POST",
            payload: {
                PageTitle: "...And All Other Mind Altering Substances",
                PageContent: "<div>new content</div>",
                Status: "ACTIVE",
                ContentType: "R",
                ImageFilename: "PAMPHLETS_All_Other"
            }
        });
    });
});
開發者ID:disco-funk,項目名稱:ca-london-angular,代碼行數:82,代碼來源:page-editor.service.spec.ts

示例3: describe

describe('Controller: LoadBalancerDetailsCtrl', function() {
  let controller: AwsLoadBalancerDetailsController;
  let $scope;
  let $state;
  const loadBalancer = {
    name: 'foo',
    region: 'us-west-1',
    account: 'test',
    accountId: 'test',
    vpcId: '1',
  };

  beforeEach(mock.module(AWS_LOAD_BALANCER_DETAILS_CTRL));

  beforeEach(
    mock.inject(($controller: IControllerService, $rootScope: IRootScopeService, _$state_: StateService) => {
      $scope = $rootScope.$new();
      $state = _$state_;
      const app = ApplicationModelBuilder.createApplicationForTests('app', { key: 'loadBalancers', lazy: true });
      app.loadBalancers.data.push(loadBalancer);
      controller = $controller(AwsLoadBalancerDetailsController, {
        $scope,
        loadBalancer,
        app,
        $state,
      });
    }),
  );

  it('should have an instantiated controller', function() {
    expect(controller).toBeDefined();
  });

  describe('Get the first subnets purpose', function() {
    it('should return empty string if there are no subnets ', function() {
      const subnetDetails: ISubnet[] = [];
      const result = controller.getFirstSubnetPurpose(subnetDetails);
      expect(result).toEqual('');
    });

    it('should return empty string if no subnetDetail is submitted', function() {
      const result = controller.getFirstSubnetPurpose();
      expect(result).toEqual('');
    });

    it('should return empty string if undefined subnetDetail is submitted', function() {
      const result = controller.getFirstSubnetPurpose(undefined);
      expect(result).toEqual('');
    });

    it('should return the first purpose of subnetDetail if there is only one', function() {
      const subnetDetails = [{ purpose: 'internal(vpc0)' }] as ISubnet[];
      const result = controller.getFirstSubnetPurpose(subnetDetails);
      expect(result).toEqual('internal(vpc0)');
    });

    it('should return the first purpose of subnetDetail if there are multiple', function() {
      const subnetDetails = [{ purpose: 'internal(vpc0)' }, { purpose: 'internal(vpc1)' }] as ISubnet[];
      const result = controller.getFirstSubnetPurpose(subnetDetails);
      expect(result).toEqual('internal(vpc0)');
    });
  });
});
開發者ID:emjburns,項目名稱:deck,代碼行數:63,代碼來源:loadBalancerDetails.controller.spec.ts

示例4: beforeEach

 beforeEach(() => {
   angular.mock.module('officeuifabric.core');
   angular.mock.module('officeuifabric.components.callout');
 });
開發者ID:sjclemmy,項目名稱:ng-officeuifabric,代碼行數:4,代碼來源:calloutDirective.spec.ts

示例5: beforeEach

 beforeEach(() => {
     angular.mock.module(PAGE_EDITOR_MODULE);
     angular.mock.module(DATA_MODULE);
 });
開發者ID:disco-funk,項目名稱:ca-london-angular,代碼行數:4,代碼來源:page-editor.service.spec.ts

示例6: beforeEach

 beforeEach(() => angular.mock.module(CORE_MODULE));
開發者ID:disco-funk,項目名稱:ca-london-angular,代碼行數:1,代碼來源:page-router.controller.spec.ts

示例7: beforeEach

  beforeEach(() => {
    angular.mock.inject(() => {
      dialogValidation = new DialogValidation();
    });

  });
開發者ID:himdel,項目名稱:ui-components,代碼行數:6,代碼來源:dialogValidationService.spec.ts

示例8: beforeEach

 beforeEach(() => angular.mock.module(MEETINGS_MODULE));
開發者ID:disco-funk,項目名稱:ca-london-angular,代碼行數:1,代碼來源:meeting-district.controller.spec.ts

示例9: describe

describe("PageRouterCtrl", () => {
    let ctrl: PageRouterCtrl, pageRouterService: PageRouterService, caLondonAppConfig: ICALondonAppConfig;
    let $controller: IControllerService, $rootScope: IRootScopeService, $scope: IScope, $q: IQService,
        $templateCache: ITemplateCacheService, $timeout: ITimeoutService, $httpBackend: IHttpBackendService,
        $window: IWindowService, $routeParams;

    beforeEach(() => angular.mock.module(CORE_MODULE));

    beforeEach(angular.mock.inject($injector => {
        $controller = $injector.get("$controller");
        $rootScope = $injector.get("$rootScope");
        $window = $injector.get("$window");
        $q = $injector.get("$q");
        $routeParams = $injector.get("$routeParams");
        $templateCache = $injector.get("$templateCache");
        $timeout = $injector.get("$timeout");
        $httpBackend = $injector.get("$httpBackend");
        $scope = $rootScope.$new(true);

        caLondonAppConfig = $injector.get("caLondonAppConfig");
        pageRouterService = $injector.get("PageRouterService");

        caLondonAppConfig.API_URL = "https://myurl.com/";

        $routeParams.pageName = "testpage";

        $httpBackend.whenGET("https://myurl.com/api/pages?contentType")
            .respond([]);
    }));

    function initController(): void {
        ctrl = $controller("PageRouterCtrl", {
            $scope: $scope
        });
    }

    describe("initialising controller", () => {
        it("should exist", () => {
            initController();
            expect(ctrl).toBeDefined();
        });

        it("should initialise and load loading page when template cache is not ready", () => {
            pageRouterService.templateLoadingState = TemplateState.NotReady;
            spyOn(pageRouterService, "getPageTitle").and.returnValue("Test Page");
            spyOn($templateCache, "get").and.callFake(page => {
                if (page === "page/testpage.html") {
                    return "<div>some template</div>";
                } else if (page === "page/disclaimmain.html") {
                    return "<div>disclaimer</div>";
                }
            });

            initController();

            expect(ctrl.pageData).toEqual([
                {PageContent: `<div id="loader"></div>`, PageTitle: "CA London"}
            ]);
            expect(ctrl.pageName).toEqual("testpage");
            expect($window.document.title).toEqual("Cocaine Anonymous London");

            pageRouterService.templateLoadingState = TemplateState.Ready;
            $timeout.flush();

            expect(ctrl.pageData).toEqual([
                {PageContent: "<div>some template</div>"},
                {PageContent: "<div>disclaimer</div>"}
            ]);
            expect(ctrl.pageName).toEqual("testpage");
            expect($window.document.title).toEqual("Test Page | Cocaine Anonymous London");
        });

        it("should load page if cache is not populated", () => {
            pageRouterService.templateLoadingState = TemplateState.Ready;
            spyOn(pageRouterService, "getPageTitle").and.returnValue("Test Page");
            spyOn($templateCache, "get").and.callFake(page => {
                if (page === "page/testpage.html") {
                    return "<div>some template</div>";
                } else if (page === "page/disclaimmain.html") {
                    return "<div>disclaimer</div>";
                }
            });

            initController();

            expect(ctrl.pageData).toEqual([
                {PageContent: "<div>some template</div>"},
                {PageContent: "<div>disclaimer</div>"}
            ]);
            expect(ctrl.pageName).toEqual("testpage");
            expect($window.document.title).toEqual("Test Page | Cocaine Anonymous London");
        });

        it("should load error page if cache has errored", () => {
            pageRouterService.templateLoadingState = TemplateState.Errored;
            spyOn(pageRouterService, "getPageTitle").and.returnValue("Error");
            spyOn($templateCache, "get").and.callFake(page => {
                if (page === "page/error.html") {
                    return "<div>error template</div>";
                }
//.........這裏部分代碼省略.........
開發者ID:disco-funk,項目名稱:ca-london-angular,代碼行數:101,代碼來源:page-router.controller.spec.ts

示例10: describe

describe("MeetingDistrictCtrl", () => {
    let ctrl: MeetingDistrictCtrl, meetingService: MeetingService;
    let $controller: IControllerService, $rootScope: IRootScopeService, $scope: IScope, $q: IQService;
    let fakeDistrictForm;

    beforeEach(() => angular.mock.module(MEETINGS_MODULE));

    beforeEach(angular.mock.inject($injector => {
        $controller = $injector.get("$controller");
        $rootScope = $injector.get("$rootScope");
        $q = $injector.get("$q");
        meetingService = $injector.get("MeetingService");

        $scope = $rootScope.$new(true);

        spyOn(meetingService, "getDistricts").and.callFake(() => {
            const deferred: IDeferred<Array<IDistrict>> = $q.defer();
            deferred.resolve(TestDistricts);
            return deferred.promise;
        });

        fakeDistrictForm = {$setPristine: () => {}};

        ctrl = $controller("MeetingDistrictCtrl", {
            $scope: $scope
        });
    }));

    it("should initialise", () => {
        expect(ctrl).toBeDefined();
        expect(ctrl.districts).toEqual([]);
        expect(ctrl.areaEditor).toEqual({
            areaStatus: ctrl.NOT_STARTED,
            editingArea: undefined,
            newAreaDescription: undefined
        });
        expect(ctrl.districtEditor.districtStatus).toEqual(ctrl.NOT_STARTED);
        expect(ctrl.districtEditor.newDistrictDescription).toBeUndefined();
        expect(ctrl.districtEditor.editingDistrict).toBeUndefined();
        expect(ctrl.isLoading).toEqual(true);

        $scope.$digest();

        expect(meetingService.getDistricts).toHaveBeenCalled();
        expect(ctrl.districts).toEqual(TestDistricts);
        expect(ctrl.areas).toEqual([
            {Area: "CENTRAL", AreaDescription: "Central"},
            {Area: "LONDON", AreaDescription: "London"},
            {Area: "UK", AreaDescription: "UK"}
        ]);
        expect(ctrl.isLoading).toEqual(false);
    });

    describe("#calculateId", () => {
        it("should calculate correct Id", () => {
            expect(ctrl.calculateId("Some area name")).toEqual("SOMEAREANA");
        });
    });

    describe("Area Form", () => {
        describe("#editArea", () => {
            it("should edit existing area", () => {
                ctrl.editArea({Area: "LONDON", AreaDescription: "London"});

                expect(ctrl.areaEditor).toEqual({
                    areaStatus: ctrl.STARTED,
                    editingArea: {Area: "LONDON", AreaDescription: "London"},
                    newAreaDescription: "London"
                });
            });

            it("should add new area", () => {
                ctrl.editArea();

                expect(ctrl.areaEditor).toEqual({
                    areaStatus: ctrl.STARTED,
                    editingArea: undefined,
                    newAreaDescription: undefined
                });
            });
        });

        describe("#cancelAddArea", () => {
            it("should cancel", () => {
                ctrl.areaEditor = {
                    areaStatus: ctrl.SUCCESS,
                    editingArea: {Area: "LONDON", AreaDescription: "London"},
                    newAreaDescription: "something"
                };

                ctrl.cancelAddArea();

                expect(ctrl.areaEditor).toEqual({
                    areaStatus: ctrl.NOT_STARTED,
                    editingArea: undefined,
                    newAreaDescription: undefined
                });
            });
        });

//.........這裏部分代碼省略.........
開發者ID:disco-funk,項目名稱:ca-london-angular,代碼行數:101,代碼來源:meeting-district.controller.spec.ts


注:本文中的angular.mock類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。