How to spyOn chained method call to Restangular in Jasmine?
<p>I am using jasmine to write unit tests for an angularJS factory that returns a call to Restangular. Take for example,</p>

<pre><code>function funcToBeTested(params) {
  return Restangular.all('/foo').getList(params);
}
</code></pre>

<p>It is straightforward to test whether or not all() is being called on Restangular. How can I test whether getList() gets called on the returned Restangular object after all() has returned?</p>

<p>At the moment, I have</p>

<pre><code>beforeEach(function() {
  module('ui.router');
  module('myService');
  module('restangular');
});

describe('funcToBeTested', function() {
  beforeEach(function() {
    httpBackend.expectGET('/foo').respond([]);
  });

  it('should call all on Restangular', function() {
    spyOn(Restangular, 'all').and.callThrough();
    funcToBeTested({});
    httpBackend.flush();
    expect(Restangular.all).toHaveBeenCalled();
  });
});
</code></pre>

<p>If I try to follow that same pattern and do something along the lines of</p>

<pre><code>expect(Restangular.all.getList).toHaveBeenCalled();
</code></pre>

<p>things stop working. I was not able to find any literature on this. Any help is appreciated.</p>