How to use the angular.mock.inject function in angular

To help you get started, we’ve selected a few angular examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spinnaker / deck / app / scripts / modules / netflix / report / reservationReport.read.service.spec.ts View on Github external
describe('ReservationReport: ', () => {

  let $http: IHttpBackendService;
  let reader: ReservationReportReader;

  beforeEach(mock.module(RESERVATION_REPORT_READER));
  beforeEach(mock.inject(($httpBackend: IHttpBackendService,
                          reservationReportReader: ReservationReportReader) => {
    $http = $httpBackend;
    reader = reservationReportReader;
  }));

  describe('test reservation retrieval', () => {

    beforeEach(() => {
      $http.whenGET(`${SETTINGS.gateUrl}/reports/reservation/v2`).respond(200, []);
    });

    it('should return a promise', () => {
      const result: IPromise = reader.getReservations();
      $http.flush();
      expect(result.then).toBeDefined();
      expect(result.catch).toBeDefined();
github spinnaker / deck / app / scripts / modules / core / src / authentication / AuthenticationInitializer.spec.ts View on Github external
beforeEach(() => (SETTINGS.authEnabled = true));
  beforeEach(() => (window.spinnakerSettings.authEnabled = true));
  beforeEach(() => AuthenticationService.reset());
  beforeEach(mock.module(AUTHENTICATION_MODULE));

  let loginRedirect: any;
  beforeAll(() => {
    loginRedirect = AuthenticationInitializer.loginRedirect;
    AuthenticationInitializer.loginRedirect = (): any => undefined;
  });
  afterAll(() => (AuthenticationInitializer.loginRedirect = loginRedirect));

  let $timeout: ng.ITimeoutService, $http: ng.IHttpBackendService, $rootScope: IDeckRootScope;

  beforeEach(
    mock.inject(
      (_$timeout_: ng.ITimeoutService, _$httpBackend_: ng.IHttpBackendService, _$rootScope_: IDeckRootScope) => {
        $timeout = _$timeout_;
        $http = _$httpBackend_;
        $rootScope = _$rootScope_;
      },
    ),
  );

  afterEach(SETTINGS.resetToOriginal);

  describe('authenticateUser', () => {
    it('requests authentication from gate, then sets authentication name field', function() {
      $http.whenGET(SETTINGS.authEndpoint).respond(200, { username: 'joe!' });
      $timeout.flush();
      $http.flush();
github spinnaker / deck / app / scripts / modules / core / src / pipeline / config / triggers / travis / travisTriggerExecutionHandler.spec.ts View on Github external
describe('Travis Trigger: ExecutionHandler', () => {
  let $scope: IScope, handler: any;

  beforeEach(mock.module(TRAVIS_TRIGGER));

  beforeEach(
    mock.inject(($rootScope: IRootScopeService, travisTriggerExecutionHandler: any) => {
      $scope = $rootScope.$new();
      handler = travisTriggerExecutionHandler;
    }),
  );

  it('returns job and master as label', () => {
    let label: string = null;
    handler.formatLabel({ job: 'a', master: 'b' }).then((result: string) => (label = result));
    $scope.$digest();
    expect(label).toBe('(Travis) b: a');
  });
});
github spinnaker / deck / app / scripts / modules / core / help / helpContents.registry.spec.ts View on Github external
describe('Help contents registry', () => {

  let registry: HelpContentsRegistry;

  beforeEach(mock.module(HELP_CONTENTS_REGISTRY));
  beforeEach(mock.inject((helpContentsRegistry: HelpContentsRegistry) => registry = helpContentsRegistry));

  describe('Override functionality', () => {
    it('overrides existing value', () => {
      registry.register('a', 'a');
      expect(registry.getHelpField('a')).toBe('a');

      registry.registerOverride('a', 'b');
      expect(registry.getHelpField('a')).toBe('b');
    });

    it('ignores subsequent registration or override registration once an override has been set', () => {
      registry.registerOverride('a', 'b');
      expect(registry.getHelpField('a')).toBe('b');

      registry.register('a', 'a');
      expect(registry.getHelpField('a')).toBe('b');
github spinnaker / deck / app / scripts / modules / core / loadBalancer / LoadBalancersTag.spec.tsx View on Github external
describe('', () => {
  const lb1 = { name: 'lb1', account: 'prod', region: 'us-east-1', vpcId: 'vpc-1' },
        lb2 = { name: 'lb2', account: 'prod', region: 'us-east-1' };

  let $q: IQService,
      $scope: IScope,
      application: Application,
      component: ReactWrapper;

  beforeEach(
    mock.module(
      APPLICATION_MODEL_BUILDER
    )
  );

  beforeEach(mock.inject((_$q_: IQService, $rootScope: IScope, applicationModelBuilder: ApplicationModelBuilder) => {
    $q = _$q_;
    $scope = $rootScope.$new();
    application = applicationModelBuilder.createApplication({
      key: 'loadBalancers',
      loader: () => $q.when(null),
      onLoad: () => $q.when(null),
      loaded: true,
    });
  }));

  it('extracts single load balancer from data', () => {
    const serverGroup = {
      account: 'prod',
      region: 'us-east-1',
      type: 'aws',
      loadBalancers: ['lb1'],
github spinnaker / deck / app / scripts / modules / core / src / cluster / filter / ClusterFilterService.spec.ts View on Github external
beforeEach(function() {
    mock.module(CLUSTER_SERVICE, require('./mockApplicationData').name, 'ui.router', REACT_MODULE);
    mock.inject(function(_applicationJSON_: any, _groupedJSON_: any, _clusterService_: any) {
      clusterService = _clusterService_;

      applicationJSON = _applicationJSON_;
      groupedJSON = _groupedJSON_;
      groupedJSON[0].subgroups[0].cluster = applicationJSON.clusters[0];
      groupedJSON[1].subgroups[0].cluster = applicationJSON.clusters[1];
    });

    this.buildApplication = (json: any) => {
      const app = ApplicationModelBuilder.createApplicationForTests('app', {
        key: 'serverGroups',
        lazy: true,
        defaultData: [],
      });
      if (json.serverGroups) {
        app.getDataSource('serverGroups').data = cloneDeep(json.serverGroups.data);
github spinnaker / deck / app / scripts / modules / core / instance / instance.write.service.spec.ts View on Github external
taskExecutor: TaskExecutor,
    $q: ng.IQService,
    $scope: ng.IScope,
    applicationModelBuilder: ApplicationModelBuilder,
    MultiselectModel: any;

  beforeEach(
    mock.module(
      INSTANCE_WRITE_SERVICE,
      APPLICATION_MODEL_BUILDER,
      require('../cluster/filter/multiselect.model')
    )
  );

  beforeEach(
    mock.inject((instanceWriter: InstanceWriter,
                 _taskExecutor_: TaskExecutor,
                 _serverGroupReader_: ServerGroupReader,
                 _$q_: ng.IQService,
                 $rootScope: ng.IRootScopeService,
                 _applicationModelBuilder_: ApplicationModelBuilder,
                 _MultiselectModel_: any) => {
      service = instanceWriter;
      taskExecutor = _taskExecutor_;
      serverGroupReader = _serverGroupReader_;
      $q = _$q_;
      $scope = $rootScope.$new();
      applicationModelBuilder = _applicationModelBuilder_;
      MultiselectModel = _MultiselectModel_;
    })
  );
github spinnaker / deck / app / scripts / modules / core / src / cache / cacheInitializer.service.spec.ts View on Github external
let accountService: AccountService;
  let securityGroupReader: SecurityGroupReader;
  let applicationReader: ApplicationReader;
  let igorService: IgorService;

  beforeEach(
    mock.module(
      CACHE_INITIALIZER_SERVICE,
      INFRASTRUCTURE_CACHE_SERVICE,
      ACCOUNT_SERVICE,
      SECURITY_GROUP_READER,
      APPLICATION_READ_SERVICE,
      IGOR_SERVICE,
    ));
  beforeEach(
    mock.inject(function (_$q_: ng.IQService,
                          _$rootScope_: ng.IRootScopeService,
                          _cacheInitializer_: CacheInitializerService,
                          _infrastructureCaches_: InfrastructureCacheService,
                          _accountService_: AccountService,
                          _securityGroupReader_: SecurityGroupReader,
                          _applicationReader_: ApplicationReader,
                          _igorService_: IgorService) {
      $q = _$q_;
      $root = _$rootScope_;
      cacheInitializer = _cacheInitializer_;
      infrastructureCache = _infrastructureCaches_;
      accountService = _accountService_;
      securityGroupReader = _securityGroupReader_;
      applicationReader = _applicationReader_;
      igorService = _igorService_;
    })
github spinnaker / deck / app / scripts / modules / core / pipeline / config / pipelineConfigProvider.spec.ts View on Github external
beforeEach(function() {
    mock.module(
      PIPELINE_CONFIG_PROVIDER,
      function(pipelineConfigProvider: PipelineConfigProvider) {
        configurer = pipelineConfigProvider;
      }
    );

    mock.inject(function($injector: auto.IInjectorService) {
      service = configurer.$get($injector);
    })
  });
github spinnaker / deck / app / scripts / modules / core / src / pipeline / config / stages / travis / travisStage.controller.spec.ts View on Github external
describe('Travis Stage Controller', () => {
  let $scope: IScope, $q: IQService, $ctrl: IControllerService;

  beforeEach(mock.module(TRAVIS_STAGE, require('angular-ui-bootstrap')));

  beforeEach(
    mock.inject(($controller: IControllerService, $rootScope: IRootScopeService, _$q_: IQService) => {
      $ctrl = $controller;
      $scope = $rootScope.$new();
      $q = _$q_;
    }),
  );

  const initialize = (stage: any): TravisStage => {
    return $ctrl(TravisStage, {
      stage,
      $scope,
    });
  };

  describe('updateJobsList', () => {
    beforeEach(() => {
      spyOn(IgorService, 'listMasters').and.returnValue($q.when([]));