Consider this method :
private subscriptions: Subscription = new Subscription();
private addFoo(): void {
this.subscriptions.add(this.fooService.createFoo(fooObj).subscribe(
(foo: Foo) => {
if (foo) {
// do something
this.isCreated = true; // coverage show that the test doest not go inside this.
}
},
(error: HttpErrorResponse) => {
if (error) {
// error handling
}
}
));
}
And the test case using jasmine:
it('should create foo successfully', () => {
spyOn(fooService, 'createFoo').and.returnValue(of(foo));
component.addFoo();
expect(component.isCreated).toBeTruthy()
})
Running test with coverage show that the line this.isCreated = true
will not be executed.. Does someone have an idea why ?