import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing'; import { LoaderComponent } from './loader.component'; import { LoaderService } from './loader.service'; import { Subscription } from 'rxjs'; describe('LoaderComponent', () => { let component: LoaderComponent; let fixture: ComponentFixture; let loader: LoaderService; beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ declarations: [LoaderComponent], }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(LoaderComponent); component = fixture.componentInstance; loader = TestBed.inject(LoaderService); component.loaderSubscription = new Subscription(); component.showLoader = false; fixture.detectChanges(); }); it('should call ngOnInit', done => { component.loaderSubscription = undefined; component.ngOnInit(); loader.startLoader(); expect(component.loaderSubscription).toBeTruthy(); done(); }); it('should call ngOnDestroy', () => { component.loaderSubscription.unsubscribe = jest.fn(); component.ngOnDestroy(); expect(component.loaderSubscription.unsubscribe).toHaveBeenCalled(); }); it('should create', () => { expect(component).toBeTruthy(); }); });