title: Jasmine check if private method has been called
body: <p>I have an Angular service exposing a public method. Inside its body two different private methods can be called according to a condition. <br><br><strong>How can I check with jasmine whether one or the other method has been called, according to the input parameter passed to the public method?</strong> I know we should not test private methods, but indeed here I just want to verify whether the public one calls the right private method. I do not want to make the private methods public, as I want only one point of access provided by the service.</p>
  
  <p><strong>My service methods:</strong></p>
  
  <pre><code>public  addOrUpdateShoppingList(list: ShoppingList) {
    if (!list) {
      return Promise.reject("List object is null!");
    }
  
    if (!list.id) { 
      return this.createNewList(list);
    }
  
    return this.updatelist(list);
  }
  
  private createNewList(list: ShoppingList) {
    const id = this.db.createId();
    list.id = id;
    return this.db.collection&lt;ShoppingList&gt;(this.SHOPPING_LIST_COLLECTION)
                  .doc(id)
                  .set(list);
  }
  
  private updatelist(list: ShoppingList) {
    return this.db.collection&lt;ShoppingList&gt;(this.SHOPPING_LIST_COLLECTION)
                  .doc(list.id)
                  .update(list);
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Jasmine test:</strong></p>
  
  <pre><code>it("addOrUpdateShoppingList should invoke createNewList() if the list doesn't have id.", () =&gt; {
  const service: DataService = TestBed.get(DataService);
  const mockedList: ShoppingList[] = [
    {
      id: null,
      isActive: true,
    }
   ];
  
  service.addOrUpdateShoppingList(newList);
  
  // I tried even with this "workaround", but it fails, even if the private method is accessed
  const sp = spyOn&lt;any&gt;(service, "createNewList").and.callThrough();
  expect(sp).toHaveBeenCalled();
  </code></pre>
  
  <p>});</p>