The issue lies within the SuperUserComponent
. The spec
file you shared pertains to the DashboardService
.
Regardless, it is recommended to create a mock service for DashboardService
and utilize it with useClass
.
Allow me to assist you in modifying the super-user.component.spec.ts
:
class export MockDashboardService{
userslastlogin(){
return of({
// Response from http call as per actual service
})
}
}
describe('SuperuserComponent', () => {
let component: SuperuserComponent;
let fixture: ComponentFixture<SuperuserComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SuperuserComponent],
imports: [ ... required imports],
providers: [
{ provide: DashboardService, useClass: MockDashboardService},
// Replace other services accordingly
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SuperuserComponent);
component = fixture.componentInstance;
})
});
If you are new to Karma and Jasmine, you may find my article on this topic helpful. Additionally, refer to this article for information on stubs and spies along with best practices.