I'm writing unit test cases in Angular 7 in this process got stuck to create unit test for a service variable 'isLoading'.
here is my app component html file:
<router-outlet></router-outlet>
<div *ngIf="guestUserService.isLoading | async" class="loaderdiv">
<mat-spinner class="loader"></mat-spinner>
</div>
The service file:
export class GuestUserService {
public isLoading: any = new BehaviorSubject(false);
}
The unit test case:
fdescribe('AppComponent', () => {
let guestUserService: any;
let guestUserServiceSpy: any;
beforeEach(async(() => {
guestUserService = jasmine.createSpyObj('GuestUserService', ['isLoading']);
TestBed.configureTestingModule({
providers: [
{ provide: GuestUserService, useValue: guestUserService }]
}).compileComponents();
}));
it('should render loader if isLoading true', () => {
guestUserServiceSpy = guestUserService.isLoading.and.returnValue(true);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(guestUserService).toBeDefined();
expect(guestUserServiceSpy).toBeDefined();
expect(guestUserService.isLoading).toBeTruthy();
expect(fixture.debugElement.query(By.css('.loader'))).toBeDefined();
expect(compiled.querySelector('mat-spinner')).toBeTruthy();
});
Getting error:
Error: InvalidPipeArgument: 'function () { return fn.apply(this, arguments); }' for pipe 'AsyncPipe'
Is there any proper way to create unit test case for this type of scenarios.