Could someone please assist me with writing a test for an ngOnInit function that includes a setTimeout() call? I am new to jasmine test cases and unsure of the correct approach. Any guidance would be greatly appreciated.
app.component.ts:
ngOnInit(): void {
if(sessionStorage.getItem("login") === "loggedIN"){
this.isNav = true;
this.isUserLogged = false;
this.loginservice.isLoggedIn = true;
setTimeout(()=>{
const isHidden = this.eleRef.nativeElement.querySelector(".header-nav-items");
isHidden.removeAttribute("hidden");
this.eleRef.nativeElement.querySelector(".]navigation").classList.remove("theme-black");
this.eleRef.nativeElement.querySelector(".horizontal-right").classList.remove("profile");
this.eleRef.nativeElement.querySelector(".horizontal-right").classList.remove("theme-black");
},500);
}
}
app.component.spec.ts :
describe('AppComponent', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ RouterTestingModule ],
schemas: [ CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA ],
declarations: [ AppComponent ]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
I have reached this point in my code implementation.