Angular Jasmine test function call inside then
<p>Here is my <strong>controller</strong> function I want to test.</p>
<pre><code>  saveItem = (): void =&gt; {
    this.updateItem();
    this.loadingDialogService.showIndicator(&quot;Saving Item&quot;);        
this._editItemService.updateItem(this.item).then((updatedItem: Item) =&gt; {
            this.loadingDialogService.cancelDialog();
            this.goToMainView();
        }).catch(() =&gt; {
            this.loadingDialogService.showErrorDialog(&quot;Failed to Save Item&quot;);
            //this._log.error(&quot;Error CallingItemService&quot;);
        });
    }
</code></pre>
<p>Here is my test:</p>
<pre><code>it(&quot;should call method saveItem&quot;, () =&gt; {
            spyOn(controller, 'updateItem');
            spyOn(loadingDialogService, 'showIndicator');
            spyOn(editItemService, 'updateItem').and.callFake(() =&gt; {
                let result: Item
                deferred.resolve(result);  
                return deferred.promise;              
            });
            spyOn(loadingDialogService, 'cancelDialog');
            spyOn(controller, 'goToMainView');
            controller.saveItem();
            expect(controller.updateItem).toHaveBeenCalled();
            expect(loadingDialogService.showIndicator).toHaveBeenCalled();
            expect(_editItemService.updateItem).toHaveBeenCalled();
            expect(loadingDialogService.cancelDialog).toHaveBeenCalled();
            expect(controller.goToMainView).toHaveBeenCalled();
        });
</code></pre>
<p>The test fails at the last two expects, throws error saying that</p>
<blockquote>
<p>Expected spy cancelDialog to have been called.</p>
<p>Expected spy goToMainView to have been called.</p>
</blockquote>
<p>I guess the test doesn't execute the functions inside <strong>then</strong> function. Could some one point out where the mistake is?</p>