I ran into very similar problems and got a working solution that makes it easy to track multiple levels.
appService = { serviceOne: jasmine.createSpy().and.returnValue({ get: jasmine.createSpy() }, serviceTwo: jasmine.createSpy().and.returnValue({ query: jasmine.createSpy() } }
This solution allows you to call the following code in unit test
expect(appService.serviceOne).toHaveBeenCalledWith('foobar'); expect(appService.serviceOne().get).toHaveBeenCalledWith('some', 'params');
Note: this code has not been tested; However, I have a very simple implementation in one of my applications. Hope this helps!
Efonzie
source share