import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { of } from 'rxjs'; import { ProfileInfo } from 'app/layouts/profiles/profile-info.model'; import { ProfileService } from 'app/layouts/profiles/profile.service'; import { PageRibbonComponent } from './page-ribbon.component'; describe('Component Tests', () => { describe('Page Ribbon Component', () => { let comp: PageRibbonComponent; let fixture: ComponentFixture; let profileService: ProfileService; beforeEach( waitForAsync(() => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule], declarations: [PageRibbonComponent], }) .overrideTemplate(PageRibbonComponent, '') .compileComponents(); }) ); beforeEach(() => { fixture = TestBed.createComponent(PageRibbonComponent); comp = fixture.componentInstance; profileService = TestBed.inject(ProfileService); }); it('Should call profileService.getProfileInfo on init', () => { // GIVEN jest.spyOn(profileService, 'getProfileInfo').mockReturnValue(of(new ProfileInfo())); // WHEN comp.ngOnInit(); // THEN expect(profileService.getProfileInfo).toHaveBeenCalled(); }); }); });