title: Karma Jasmine - Code Coverage does not coverring functions inside Observable's subscribe method
body: <p>I am doing a Unit Test on one of the methods of component in my angular 10 project</p>
  <p>and I saw this code:</p>
  <p><strong>MessageListComponent.ts</strong></p>
  <p>EDIT: updating the complete code (the answer is already in the comment of this post)</p>
  <pre><code>@Component({
      selector: 'app-message-list',
      template: ...,
      providers: [
          MessageService
      ]
  })
  export class MessageListComponent {
  
      constructor(private messageService: MessageService) {}
  
      ngOnInit() {
          // other implementation
          ....
      
          this.GetAllContents();
      }
      GetAllContents() {
          if(this.subscribedMessage) {
              this.subscribedMessage.unsubscribe();
          }
          this.subscribedMessage = this.messageService.getAllContents().subscribe((data) =&gt; {
              data &amp;&amp; data.forEach(item =&gt; this.dataList.push(item));
              // further codes here
              ...
          }, 
          () =&gt; {
              // further codes here
              ...
          });
  
          // further codes here
          ...
      }
  
  }
  </code></pre>
  <p>and I created a spec file like so:</p>
  <p><strong>MessageListComponent.spec.ts</strong></p>
  <pre><code>describe('MessageListComponent', () =&gt; {
      let fixture: ComponentFixture&lt;MessageListComponent&gt;;
      let component: MessageListComponent;
      let messageService: MessageService;
      beforeEach(() =&gt; {
          // TestBed configuration
          TestBed.configureTestingModule({
              ....
              providers: [
                  MessageService,
                  ....
              ]
          }).compileComponents();
      });
  
      beforeEach(() =&gt; {
          messageService = TestBed.inject(MessageService);
          messageService.getAllContents = jasmine.createSpy().and.returnValue(observableOf(&lt;any[]&gt;[{}]));
          fixture = TestBed.createComponent(MessageListComponent);
          component = fixture.componentInstance;
          fixture.detectChanges();
      });
  
      it('should load', () =&gt; {
          expect(messageService.getAllContents).toHaveBeenCalled();
      });
  });
      
  </code></pre>
  <p>when I run the ng test --code-coverage=true</p>
  <p>the coverage got the implementation inside <code>GetAllContents</code> method of <code>MessageListComponent</code> but the function inside the subscribe method is not getting covered by the coverage</p>
  <p>Is there something I'm missing to get the function inside the subscribe method?</p>