Gist:
I spy on get method of my rest service:
spyOn(restService, 'get').and.callFake(function () { return deferred.promise; });
The method I am trying to test is myService.getFormData() that returns a chained promise:
function getFormData() { var getPromise = this.restService.get(endPoint, params, true); var processedDataPromise = then(successHandle, failHandler); return processedDataPromise; }
Back to Jasmine spec, I invoke getFormData function and make assertions:
var processedDataPromise = myService.getFormData(); processedDataPromise.then(function(data) { expect(data).not.toBeNull(); }); deferred.resolve(testFormData); $rootScope.$digest();
The Problem:
The above derivative promise (processedDataPromise) does indeed get resolved. However the 'data' passed to it is undefined. Is it anything to do with $digest cycles not doing its job in Jasmine?
Why does Jasmine not pass any data to the above derived promise.?
Further Note: The processedDataPromise is a completely new promise than the get returned promise.
It is a promise for processedData which as we can see is returned by successHandle (Definition not shown) once its parent getPromise gets resolved.
In UI everything works like a Charm.