当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mock.module方法代码示例

本文整理汇总了TypeScript中angular.mock.module方法的典型用法代码示例。如果您正苦于以下问题:TypeScript mock.module方法的具体用法?TypeScript mock.module怎么用?TypeScript mock.module使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在angular.mock的用法示例。


在下文中一共展示了mock.module方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: beforeEach

 beforeEach(() => {
   ng.mock.module('officeuifabric.core');
   ng.mock.module('officeuifabric.components.contextualmenu');
 });
开发者ID:Acaspita,项目名称:ng-officeuifabric,代码行数:4,代码来源:contextualMenu.spec.ts

示例2: beforeEach

 beforeEach(() => {
     angular.mock.module('officeuifabric.core');
     angular.mock.module('officeuifabric.components.searchbox');
 });
开发者ID:sjclemmy,项目名称:ng-officeuifabric,代码行数:4,代码来源:searchboxDirective.spec.ts

示例3: describe

describe('Api', () => {
  beforeEach(angular.mock.module('gantt'))

  let GanttApi
  let scope: IRootScopeService

  beforeEach(angular.mock.inject(['$rootScope', 'GanttApi', function ($tRootScope: IRootScopeService, tGanttApi) {
    GanttApi = tGanttApi
    scope = $tRootScope
  }]))

  it('Register and Unregister events properly',
    function () {
      let api = new GanttApi(this)

      let called1 = false
      let called2 = false

      api.registerEvent('test', 'called')
      this.testMethod = function () {
        called1 = true
        api.test.raise.called()
      }

      let unregister = api.test.on.called(scope, function () {
        called2 = true
      })

      this.testMethod()

      expect(called1).to.be.ok
      expect(called2).to.be.ok

      called1 = false
      called2 = false

      unregister()

      this.testMethod()

      expect(called1).to.be.ok
      expect(called2).to.be.not.ok
    }
  )

  it('Can temporary suppress events',
    function () {
      let api = new GanttApi(this)

      let called1 = false
      let called2 = false

      let self = this

      api.registerEvent('test', 'called')
      this.testMethod = function () {
        called1 = true
        api.test.raise.called()
      }

      let calledHandler = function () {
        called2 = true
      }
      api.test.on.called(scope, calledHandler)

      api.suppressEvents(calledHandler, function () {
        self.testMethod()
      })

      expect(called1).to.be.ok
      expect(called2).to.be.not.ok

      called1 = false
      called2 = false

      this.testMethod()

      expect(called1).to.be.ok
      expect(called2).to.be.ok
    }
  )
})
开发者ID:angular-gantt,项目名称:angular-gantt,代码行数:82,代码来源:api.spec.ts

示例4: describe

describe('Service: securityGroupReader', function() {
  let $q: ng.IQService, $http: ng.IHttpBackendService, $scope: ng.IRootScopeService, reader: SecurityGroupReader;

  beforeEach(mock.module(SECURITY_GROUP_TRANSFORMER_SERVICE, SECURITY_GROUP_READER));
  beforeEach(
    mock.inject(function(
      _$q_: ng.IQService,
      $httpBackend: ng.IHttpBackendService,
      $rootScope: ng.IRootScopeService,
      _providerServiceDelegate_: any,
      securityGroupTransformer: SecurityGroupTransformerService,
      _securityGroupReader_: SecurityGroupReader,
    ) {
      reader = _securityGroupReader_;
      $http = $httpBackend;
      $q = _$q_;
      $scope = $rootScope.$new();

      const cacheStub: any = {
        get: () => null as any,
        put: () => {},
      };
      spyOn(InfrastructureCaches, 'get').and.returnValue(cacheStub);

      spyOn(securityGroupTransformer, 'normalizeSecurityGroup').and.callFake((securityGroup: ISecurityGroup) => {
        return $q.when(securityGroup);
      });
      spyOn(_providerServiceDelegate_, 'getDelegate').and.returnValue({
        resolveIndexedSecurityGroup: (idx: any, container: ISecurityGroup, id: string) => {
          return idx[container.account][container.region][id];
        },
      });
    }),
  );

  it('attaches load balancer to firewall usages', function() {
    let data: any[] = null;

    const application: Application = ApplicationModelBuilder.createApplicationForTests(
      'app',
      {
        key: 'securityGroups',
        loader: () => $q.resolve([]),
        onLoad: (_app, _data) => $q.resolve(_data),
      },
      {
        key: 'serverGroups',
        loader: () => $q.resolve([]),
        onLoad: (_app, _data) => $q.resolve(_data),
      },
      {
        key: 'loadBalancers',
        loader: () =>
          $q.resolve([
            {
              name: 'my-elb',
              account: 'test',
              region: 'us-east-1',
              securityGroups: ['not-cached'],
            },
          ]),
        onLoad: (_app, _data) => $q.resolve(_data),
      },
    );

    application.serverGroups.refresh();
    application.loadBalancers.refresh();
    $scope.$digest();

    $http.expectGET(`${API.baseUrl}/securityGroups`).respond(200, {
      test: {
        aws: {
          'us-east-1': [{ name: 'not-cached' }],
        },
      },
    });
    reader.getApplicationSecurityGroups(application, null).then((results: any[]) => (data = results));
    $http.flush();
    $scope.$digest();
    const group: ISecurityGroup = data[0];
    expect(group.name).toBe('not-cached');
    expect(group.usages.loadBalancers[0]).toEqual({ name: application.getDataSource('loadBalancers').data[0].name });
  });

  it('adds firewall names across accounts, falling back to the ID if none found', function() {
    let details: ISecurityGroupDetail = null;
    const application: Application = ApplicationModelBuilder.createApplicationForTests('app');
    application['securityGroupsIndex'] = {
      test: { 'us-east-1': { 'sg-2': { name: 'matched' } } },
      prod: { 'us-east-1': { 'sg-2': { name: 'matched-prod' } } },
    };

    $http.expectGET(`${API.baseUrl}/securityGroups/test/us-east-1/sg-123?provider=aws&vpcId=vpc-1`).respond(200, {
      inboundRules: [
        { securityGroup: { accountName: 'test', id: 'sg-345' } },
        { securityGroup: { accountName: 'test', id: 'sg-2' } },
        { securityGroup: { accountName: 'prod', id: 'sg-2' } },
      ],
      region: 'us-east-1',
    });
//.........这里部分代码省略.........
开发者ID:emjburns,项目名称:deck,代码行数:101,代码来源:securityGroupReader.service.spec.ts

示例5: beforeEach

	beforeEach(() => {
		angular.mock.module(moduleName);

		let services: any = __test.angularFixture.inject(serviceName);
		formService = services[serviceName];
	});
开发者ID:ibedard16,项目名称:TypeScript-Angular-Components,代码行数:6,代码来源:form.service.tests.ts

示例6: describe

describe('entityTags reader', () => {

  let $http: ng.IHttpBackendService;
  let $q: ng.IQService;
  let $timeout: ng.ITimeoutService;
  let $exceptionHandler: ng.IExceptionHandlerService;
  let service: EntityTagsReader;

  beforeEach(function () {
    // Why do we have to clear the settings file? What setting is causing retries to not work?
    Object.keys(SETTINGS).forEach(key => {
      SETTINGS[key] = undefined;
    });
    SETTINGS.gateUrl = 'http://gate';
    SETTINGS.entityTags = { maxUrlLength: 55 };
  });

  beforeEach(mock.module(ENTITY_TAGS_READ_SERVICE));

  beforeEach(mock.module(($exceptionHandlerProvider: ng.IExceptionHandlerProvider) => {
    $exceptionHandlerProvider.mode('log');
  }));

  beforeEach(
    mock.inject(($httpBackend: ng.IHttpBackendService,
                 _$q_: ng.IQService,
                 _$exceptionHandler_: ng.IExceptionHandlerService,
                 entityTagsReader: EntityTagsReader,
                 _$timeout_: ng.ITimeoutService) => {
      $http = $httpBackend;
      $q = _$q_;
      service = entityTagsReader;
      $exceptionHandler = _$exceptionHandler_;
      $timeout = _$timeout_;
    }));

  afterEach(SETTINGS.resetToOriginal);

  it('returns an empty list instead of failing if tags cannot be loaded', () => {
    $http.whenGET(`${SETTINGS.gateUrl}/tags?entityId=a,b&entityType=servergroups`).respond(400, 'bad request');
    let result: any = null;
    service.getAllEntityTags('serverGroups', ['a', 'b']).then(r => result = r);
    $http.flush();
    $timeout.flush();
    $http.flush();
    expect(result).toEqual([]);
    expect(($exceptionHandler as any)['errors'].length).toBe(1);
  });

  it('collates entries into groups when there are too many', () => {
    $http.expectGET(`http://gate/tags?entityId=a,b&entityType=servergroups`).respond(200, []);
    $http.expectGET(`http://gate/tags?entityId=c,d&entityType=servergroups`).respond(200, []);

    let result: any = null;
    service.getAllEntityTags('serverGroups', ['a', 'b', 'c', 'd']).then(r => result = r);
    $http.flush();
    $timeout.flush();
    expect(result).toEqual([]);
    expect(($exceptionHandler as any)['errors'].length).toBe(0);
  });

  it('retries server group fetch once on exceptions', () => {
    $http.expectGET(`${SETTINGS.gateUrl}/tags?entityId=a,b&entityType=servergroups`).respond(400, 'bad request');
    let result: any = null;
    service.getAllEntityTags('serverGroups', ['a', 'b']).then(r => result = r);
    $http.flush();
    $http.expectGET(`${SETTINGS.gateUrl}/tags?entityId=a,b&entityType=servergroups`).respond(200, []);
    $timeout.flush();
    $http.flush();
    expect(result).toEqual([]);
    expect(($exceptionHandler as any)['errors'].length).toBe(0);
  });
});
开发者ID:brujoand,项目名称:deck,代码行数:73,代码来源:entityTags.read.service.spec.ts

示例7: describe

describe('serverGroupWarningMessageService', () => {
  let service: ServerGroupWarningMessageService,
      applicationModelBuilder: ApplicationModelBuilder,
      app: Application,
      serverGroup: IServerGroup;

  beforeEach(mock.module(SERVER_GROUP_WARNING_MESSAGE_SERVICE, APPLICATION_MODEL_BUILDER));

  beforeEach(mock.inject((serverGroupWarningMessageService: ServerGroupWarningMessageService,
                          _applicationModelBuilder_: ApplicationModelBuilder) => {
    service = serverGroupWarningMessageService;
    applicationModelBuilder = _applicationModelBuilder_;
    app = applicationModelBuilder.createApplication('app');
  }));

  describe('addDestroyWarningMessage', () => {
    it('leaves parameters unchanged when additional server groups exist in cluster', () => {
      serverGroup = {
        account: 'test',
        cloudProvider: 'aws',
        cluster: 'foo',
        instanceCounts: { up: 0, down: 0, succeeded: 0, failed: 0, unknown: 0, outOfService: 0, starting: 0 },
        instances: [],
        name: 'foo-v000',
        region: 'us-east-1',
        type: 'a'
      };

        app.clusters = [
        {
          name: 'foo',
          account: 'test',
          cloudProvider: '',
          category: '',
          serverGroups: [
            serverGroup,
            { account: 'test', cloudProvider: 'aws', cluster: 'foo', instanceCounts: { up: 0, down: 0, succeeded: 0, failed: 0, unknown: 0, outOfService: 0, starting: 0 }, instances: [], name: 'foo-v001', region: 'us-east-1', type: 'a' },
          ]
        }
      ];
      const params: IConfirmationModalParams = {};
      service.addDestroyWarningMessage(app, serverGroup, params);
      expect(params.body).toBeUndefined();
    });

    it('adds a body to the parameters with cluster name, region, account when this is the last server group', () => {
      serverGroup = {
        account: 'test',
        cloudProvider: 'aws',
        cluster: 'foo',
        instanceCounts: { up: 0, down: 0, succeeded: 0, failed: 0, unknown: 0, outOfService: 0, starting: 0 },
        instances: [],
        name: 'foo-v000',
        region: 'us-east-1',
        type: 'a'
      };

      app.clusters = [
        {
          name: 'foo',
          account: 'test',
          cloudProvider: '',
          category: '',
          serverGroups: [serverGroup]
        }
      ];
      const params: IConfirmationModalParams = {};
      service.addDestroyWarningMessage(app, serverGroup, params);
      expect(params.body).toBeDefined();
      expect(params.body.includes('You are destroying the last Server Group in the Cluster')).toBe(true);
      expect(params.body.includes('test')).toBe(true);
      expect(params.body.includes('foo')).toBe(true);
      expect(params.body.includes('us-east-1')).toBe(true);
    });
  });

  describe('addDisableWarningMessage', () => {
    it('leaves parameters unchanged when server group has no instances', () => {
      serverGroup = {
        account: 'test',
        cloudProvider: 'aws',
        cluster: 'foo',
        instanceCounts: { up: 0, down: 0, succeeded: 0, failed: 0, unknown: 0, outOfService: 0, starting: 0 },
        instances: [],
        name: 'foo-v000',
        region: 'us-east-1',
        type: 'a'
      };

      app.clusters = [
        {
          name: 'foo',
          account: 'test',
          cloudProvider: '',
          category: '',
          serverGroups: [serverGroup]
        }
      ];
      const params: IConfirmationModalParams = {};
      service.addDisableWarningMessage(app, serverGroup, params);
//.........这里部分代码省略.........
开发者ID:robfletcher,项目名称:deck,代码行数:101,代码来源:serverGroupWarningMessage.service.spec.ts

示例8: describe

describe(`ng-infinite-autocomplete Wrapper Unit Testing`, function() {

    var InfiniteAutocompleteCore, $compile, element, $scope;

    beforeEach(angular.mock.module('infinite-autocomplete'));
    
    beforeEach(angular.mock.module(($provide:ng.auto.IProvideService) => {
		InfiniteAutocompleteCore = jasmine.createSpy('InfiniteAutocompleteCore');
        InfiniteAutocompleteCore.prototype.destroy = jasmine.createSpy('destroy');
        InfiniteAutocompleteCore.prototype.setConfig = jasmine.createSpy('setConfig')
            //Mock passed functions to be executed automatically to bypass low coverage report
            //Depends on the CORE Unit Testing 
            .and.callFake(function(config) { 
                if(config.onSelect) {
                    config.onSelect();
                }
                if(config.onLoadingStateChange) {
                  config.onLoadingStateChange();
                }
                if(config.onError) {
                  config.onError();
                }
                if(config.getDataFromApi) {
                    config.getDataFromApi();
                }
            });
		$provide.constant('InfiniteAutocompleteCore', InfiniteAutocompleteCore);
	}));

    beforeEach(inject(($injector) => {
        $scope = $injector.get(`$rootScope`).$new();
        $compile = $injector.get(`$compile`);
    }));

    
    describe(`ng-infinite-autocomplete as attribute`, function() {
        it(`should work as expected and call InfiniteAutocomplete core plugin`, function() {
            $scope.data = [{
                text: 'text', value: 'value'
            }];
            element = $compile('<div ng-infinite-autocomplete data="data"></div>')($scope);

            $scope.$digest();

            expect(InfiniteAutocompleteCore)
                .toHaveBeenCalledWith(element[0]);
        });
    });

    describe(`destroy lifecycle hook`, function() {
        it(`should call InfiniteAutocompleteCore.prototype.destroy when scope get destroy`, 
            function() {
                $scope.data = [{
                text: 'text', value: 'value'
            }];
            element = $compile('<div ng-infinite-autocomplete data="data"></div>')($scope);

            $scope.$digest();

            expect(InfiniteAutocompleteCore)
                .toHaveBeenCalledWith(element[0]);
            $scope.$destroy();
            expect(InfiniteAutocompleteCore.prototype.destroy)
                .toHaveBeenCalled();
        });
    });

    describe(`value feature support`, function() {

      it(`should pass the value to the CORE.setConfig`, function() {
          $scope.onErrorHandler = () => {};
          $scope.data = [
              { text: 'first', value: 1 }
          ];
          $scope.value = "what!";

          element = $compile(`<ng-infinite-autocomplete
                                          ng-model="value"
                                          data="data">
                              </ng-infinite-autocomplete>`)($scope);

          $scope.$digest();
          
          expect(InfiniteAutocompleteCore)
              .toHaveBeenCalledWith(element[0]);

          expect(InfiniteAutocompleteCore.prototype.setConfig)
              .toHaveBeenCalledWith({
                value: "what!"
              });

      });

    });

    describe(`Data feature support`, function() {

        it(`should pass the data into the InfiniteAutocomplete core plugin`, function() {
            $scope.data = [{
                text: 'text', value: 'value'
//.........这里部分代码省略.........
开发者ID:Attrash-Islam,项目名称:ng-infinite-autocomplete,代码行数:101,代码来源:index.ts

示例9: describe

describe("scheduleModel", (): void => {
	let	scheduleModel: ScheduleModel,
			$httpBackend: angular.IHttpBackendService,
			payeeModel: PayeeModelMock,
			categoryModel: CategoryModelMock,
			securityModel: SecurityModelMock;

	// Load the modules
	beforeEach(angular.mock.module("lootMocks", "lootSchedules", (mockDependenciesProvider: MockDependenciesProvider): void => mockDependenciesProvider.load(["payeeModel", "categoryModel", "securityModel"])));

	// Inject the object under test and it's remaining dependencies
	beforeEach(inject((_scheduleModel_: ScheduleModel, _$httpBackend_: angular.IHttpBackendService, _payeeModel_: PayeeModelMock, _categoryModel_: CategoryModelMock, _securityModel_: SecurityModelMock): void => {
		scheduleModel = _scheduleModel_;

		$httpBackend = _$httpBackend_;

		payeeModel = _payeeModel_;
		categoryModel = _categoryModel_;
		securityModel = _securityModel_;
	}));

	// After each spec, verify that there are no outstanding http expectations or requests
	afterEach((): void => {
		$httpBackend.verifyNoOutstandingExpectation();
		$httpBackend.verifyNoOutstandingRequest();
	});

	describe("path", (): void => {
		it("should return the schedules collection path when an id is not provided", (): Chai.Assertion => scheduleModel.path().should.equal("/schedules"));

		it("should return a specific schedule path when an id is provided", (): Chai.Assertion => scheduleModel.path(123).should.equal("/schedules/123"));
	});

	describe("parse", (): void => {
		let schedule: ScheduledTransaction;

		beforeEach((): ScheduledTransaction => (schedule = scheduleModel["parse"](createScheduledBasicTransaction({next_due_date: format(new Date(), "YYYY-MM-DD HH:mm:ss")}))));

		it("should convert the next due date from a string to a date", (): void => {
			schedule.next_due_date.should.be.a("date");
			schedule.next_due_date.should.deep.equal(startOfDay(new Date()));
		});
	});

	describe("stringify", (): void => {
		let schedule: ScheduledTransaction;

		beforeEach((): ScheduledTransaction => (schedule = scheduleModel["stringify"](createScheduledBasicTransaction({next_due_date: startOfDay(new Date())}))));

		it("should convert the next due date from a date to a string", (): void => {
			schedule.next_due_date.should.be.a("string");
			schedule.next_due_date.should.deep.equal(format(new Date(), "YYYY-MM-DD"));
		});
	});

	describe("all", (): void => {
		const expectedResponse: string[] = ["schedule 1", "schedule 2"];
		let actualResponse: angular.IPromise<ScheduledTransaction[]>;

		beforeEach((): void => {
			scheduleModel["parse"] = sinon.stub().returnsArg(0);
			$httpBackend.expectGET(/schedules/).respond(200, expectedResponse);
			actualResponse = scheduleModel.all();
			$httpBackend.flush();
		});

		it("should dispatch a GET request to /schedules", (): null => null);

		it("should parse each schedule returned", (): Chai.Assertion => scheduleModel["parse"].should.have.been.calledTwice);

		it("should return a list of all schedules", (): void => {
			actualResponse.should.eventually.deep.equal(expectedResponse);
		});
	});

	describe("save", (): void => {
		const expectedResponse: string = "schedule";

		beforeEach((): void => {
			scheduleModel["stringify"] = sinon.stub().returnsArg(0);
			scheduleModel["parse"] = sinon.stub().returnsArg(0);
			$httpBackend.whenPOST(/schedules$/).respond(200, expectedResponse);
			$httpBackend.whenPATCH(/schedules\/1$/).respond(200, expectedResponse);
		});

		it("should flush the payee cache when the schedule payee is new", (): void => {
			scheduleModel.save(createScheduledBasicTransaction({id: 1, payee: ""}));
			payeeModel.flush.should.have.been.called;
			$httpBackend.flush();
		});

		it("should not flush the payee cache when the schedule payee is existing", (): void => {
			scheduleModel.save(createScheduledBasicTransaction({id: 1}));
			payeeModel.flush.should.not.have.been.called;
			$httpBackend.flush();
		});

		it("should flush the category cache when the schedule category is new", (): void => {
			scheduleModel.save(createScheduledBasicTransaction({id: 1, category: ""}));
			categoryModel.flush.should.have.been.called;
//.........这里部分代码省略.........
开发者ID:scottohara,项目名称:loot,代码行数:101,代码来源:schedule.ts

示例10: beforeEach

 beforeEach(() => angular.mock.module(COMMON_MODULE));
开发者ID:disco-funk,项目名称:ca-london-angular,代码行数:1,代码来源:alert-modal-instance.controller.spec.ts


注:本文中的angular.mock.module方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。