How to use the @angular/core/testing.inject function in @angular/core

To help you get started, we’ve selected a few @angular/core 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 syndesisio / syndesis-ui / src / app / +user / profile / profile.spec.ts View on Github external
// provide a better mock
            {
                provide: ActivatedRoute,
                useValue: {
                    data: {
                        subscribe: (fn) => fn({
                            yourData: 'yolo'
                        })
                    }
                }
            },
            Profile
        ]
    }));
    
    it('should log ngOnInit', inject([Profile], (profile) => {
        spyOn(console, 'log');
        expect(console.log).not.toHaveBeenCalled();
        
        profile.ngOnInit();
        expect(console.log).toHaveBeenCalled();
    }));
    
});
github chrisguttandin / angular-audio-context / test / unit / module.ts View on Github external
describe('forRoot()', () => {

        let audioContext: IAudioContext;
        let isSupported: () => Promise;

        beforeEach(() => {
            TestBed.configureTestingModule({
                imports: [
                    AudioContextModule.forRoot('balanced')
                ]
            });
        });

        beforeEach(inject([ Injector ], (injector: Injector) => {
            audioContext = injector.get(AudioContext);
            isSupported = injector.get<() => Promise>(audioContextModuleIsSupported);
        }));

        it('should provide an instance of the AudioContext class from standardized-audio-context module', () => {
            expect(audioContext instanceof standardizedAudioContextAudioContext).toBe(true);
        });

        it('should provide the isSupported() function from standardized-audio-context module', () => {
            expect(isSupported).toBe(standardizedAudioContextIsSupported);
        });

    });
github jasontaylordev / CleanArchitecture / src / WebUI / ClientApp / src / api-authorization / authorize.interceptor.spec.ts View on Github external
describe('AuthorizeInterceptor', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [AuthorizeInterceptor]
    });
  });

  it('should be created', inject([AuthorizeInterceptor], (service: AuthorizeInterceptor) => {
    expect(service).toBeTruthy();
  }));
});
github Squidex / squidex / frontend / app / shared / services / translations.service.spec.ts View on Github external
describe('TranslationsService', () => {
    beforeEach(() => {
        TestBed.configureTestingModule({
            imports: [
                HttpClientTestingModule
            ],
            providers: [
                TranslationsService,
                { provide: ApiUrlConfig, useValue: new ApiUrlConfig('http://service/p/') }
            ]
        });
    });

    afterEach(inject([HttpTestingController], (httpMock: HttpTestingController) => {
        httpMock.verify();
    }));

    it('should make post request to translate text',
        inject([TranslationsService, HttpTestingController], (translationsService: TranslationsService, httpMock: HttpTestingController) => {

        const dto = { text: 'Hello', sourceLanguage: 'en', targetLanguage: 'de' };

        let translation: TranslationDto;

        translationsService.translate('my-app', dto).subscribe(result => {
            translation = result;
        });

        const req = httpMock.expectOne('http://service/p/api/apps/my-app/translations');
github EvictionLab / eviction-maps / src / app / map-tool / map / map.service.spec.ts View on Github external
});
      service.setMapInstance(mapboxStub);
      service.getUnionFeature('layer', featureStub);
    }
  ));

  it('should not call queryRenderedFeatures in getUnionFeature if not bbox, but close to area',
    inject([MapService], (service: MapService) => {
      mapboxStub.queryRenderedFeatures = (a, b) => [];
      service.setMapInstance(mapboxStub);
      expect(service.getUnionFeature('layer', featureStub)).toBeTruthy();
    }
  ));

  it('highlight features should create a union feature if rendered features are present',
    inject([MapService], (service: MapService) => {
      service.setMapInstance(mapboxStub);
      spyOn(service, 'isHighlightVisible').and.returnValue(true);
      spy = spyOn(service, 'getUnionFeature').and.returnValue(featureStub);
      service.updateHighlightFeatures([mapFeatureStub]);
      expect(service.getUnionFeature).toHaveBeenCalledWith('layer', mapFeatureStub);
    }
  ));

  it('highlight feature should use existing feature, updating color if in current features',
    inject([MapService], (service: MapService) => {
      service.setMapInstance(mapboxStub);
      const altFeature = featureStub;
      altFeature.properties = {
        ...altFeature.properties, alt: true
      };
      spyOn(service, 'getActiveFeature').and.returnValue(altFeature);
github Sunbird-Ed / SunbirdEd-portal / src / app / client / src / app / modules / workspace / components / flagged / flagged.component.spec.ts View on Github external
component.navigateToPage(1);
    expect(route.navigate).toHaveBeenCalledWith(['workspace/content/flagged', component.pageNumber]);
  }));

  it('should call setpage method and set  page number zero and return it  ', inject([SearchService, Router], (searchService,
    route) => {
    const userService = TestBed.get(UserService);
    const learnerService = TestBed.get(LearnerService);
    spyOn(learnerService, 'get').and.returnValue(observableOf(Response.userSuccess.success));
    userService._userProfile = mockroleOrgMap;
    component.pager = Response.pager;
    component.pager.totalPages = 0;
    component.navigateToPage(0);
  }));

  it('should call contentClick method and open content player  ', inject([SearchService, Router], (searchService,
    route) => {
    const userService = TestBed.get(UserService);
    const learnerService = TestBed.get(LearnerService);
    spyOn(learnerService, 'get').and.returnValue(observableOf(Response.userSuccess.success));
    userService._userProfile = mockroleOrgMap;
    const content = { data: { metaData: { 'mimeType': 'application/vnd.ekstep.ecml-archive', 'identifier': 'do_112485749070602240134' } } };
    component.contentClick(content);
  }));
  it('should call inview method for visits data', () => {
    component.telemetryImpression = Response.telemetryData;
    spyOn(component, 'inview').and.callThrough();
    component.inview(Response.event);
    expect(component.inview).toHaveBeenCalled();
    expect(component.inviewLogs).toBeDefined();
  });
});
github bkimminich / juice-shop / frontend / src / app / Services / administration.service.spec.ts View on Github external
describe('AdministrationService', () => {
  beforeEach(() => {

    TestBed.configureTestingModule({
      imports: [HttpClientTestingModule],
      providers: [AdministrationService]
    })
  })

  it('should be created', inject([AdministrationService], (service: AdministrationService) => {
    expect(service).toBeTruthy()
  }))

  it('should get application version directly from the rest api', inject([AdministrationService, HttpTestingController],
    fakeAsync((service: AdministrationService, httpMock: HttpTestingController) => {
      let res: any
      service.getApplicationVersion().subscribe((data) => res = data)
      const req = httpMock.expectOne('http://localhost:3000/rest/admin/application-version')
      req.flush({ version: 'apiResponse' })
      tick()

      expect(req.request.method).toBe('GET')
      expect(res).toBe('apiResponse')
      httpMock.verify()
    })
  ))
github rabix / composer / src / app / editor-common / cwl-schema-validation-worker / cwl-schema-validation-worker.service.spec.ts View on Github external
describe("CwlSchemaValidationWorkerService", () => {
    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [CwlSchemaValidationWorkerService]
        });
    });

    it("should ...", inject([CwlSchemaValidationWorkerService], (service: CwlSchemaValidationWorkerService) => {
        expect(service).toBeTruthy();
    }));
});
github angulartics / angulartics2 / src / lib / providers / ibm-digital-analytics / ibm-digital-analytics.spec.ts View on Github external
describe('while active', () => {
        beforeEach(() => {
            window.cmCreatePageviewTag = jasmine.createSpy('cmCreatePageviewTag');
            window.cmCreateProductviewTag = jasmine.createSpy('cmCreateProductviewTag');
            window.cmCreateShopAction5Tag = jasmine.createSpy('cmCreateShopAction5Tag');
            window.cmCreateShopAction9Tag = jasmine.createSpy('cmCreateShopAction9Tag');
            window.cmCreateOrderTag = jasmine.createSpy('cmCreateOrderTag');
            window.cmCreateRegistrationTag = jasmine.createSpy('cmCreateRegistrationTag');
            window.cmCreateElementTag = jasmine.createSpy('cmCreateElementTag');
            window.cmCreateConversionEventTag = jasmine.createSpy('cmCreateConversionEventTag');
            window.cmDisplayShops = jasmine.createSpy('cmDisplayShops');
        });

        it('should track pages',
            fakeAsync(inject([Angulartics2, Angulartics2IBMDigitalAnalytics],
                (angulartics2: Angulartics2, angulartics2IBMDigitalAnalytics: Angulartics2IBMDigitalAnalytics) => {
                    fixture = createRoot(RootCmp);
                    angulartics2.pageTrack.next({ path: '/abc' });
                    advance(fixture);
                    expect(window.cmCreatePageviewTag).toHaveBeenCalledWith('/abc', null, null, null);
                }),
            ),
        );

        it('should track cmCreateProductviewTag event',
            fakeAsync(inject([Angulartics2, Angulartics2IBMDigitalAnalytics],
                (angulartics2: Angulartics2, angulartics2IBMDigitalAnalytics: Angulartics2IBMDigitalAnalytics) => {
                    fixture = createRoot(RootCmp);
                    angulartics2.eventTrack.next({
                        action: 'cmCreateProductviewTag',
                        properties: {
github articodeltd / angular-cesium / src / services / drawers / static-polyline-drawer / static-polyline-drawer-service.spec.ts View on Github external
spy.calls.reset();
      staticPolylineProps.ready = null;
      staticPolylineProps.readyPromise = Promise.resolve(staticPolylineProps);
      service.update(staticPolylineProps, null, staticPolylineAttribute, null);
      tick();
      expect(staticPolylineProps.getGeometryInstanceAttributes).toHaveBeenCalled();
    })));

  it('should throw if positions is not given', inject([StaticPolylineDrawerService], (service: StaticPolylineDrawerService) => {
    staticPolylineProps.geometry.positions = undefined;

    expect(() => service.add(staticPolylineProps.geometry, staticPolylineProps.attributes, staticPolylineProps.appearance)).toThrow();
  }));

  it('should throw if appearance is not given', inject([StaticPolylineDrawerService], (service: StaticPolylineDrawerService) => {
    staticPolylineProps.appearance = undefined;

    expect(() => service.add(staticPolylineProps.geometry, staticPolylineProps.attributes, staticPolylineProps.appearance)).toThrow();
  }));
});