Reputation: 1377
I have the following code: (beforeEach)
spyOn(HttpService, 'post').and.callFake(function (url, paging, targetSpinner) {
return $q.when(_fakeServerResponse);
});
The test case:
it('should compare size', function () {
service.get({},'','').then(function (serviceResponse) {
expect(serviceResponse.x).toEqual(_fakeServerResponse.x);
and the get method:
return httpService.post(apiUrls).then(postComplete)
My problem is, as mentioned in the title: some why jasmine says that there are not expectations.
The service itself when not running a test is used:
myService.get(data, param1, param2).then(getComplete);
I will also add that when running the spec case, getComplete is never called, which is the source of the problem as I see it (yet I don't know why it doesn't get called).
Thanks
Upvotes: 0
Views: 2585
Reputation: 692181
$q is asynchronous. The returned promise will only be resolved at the next scope digest. Your test should rather look like:
it('should compare size', inject(function($rootScope) {
var actualX;
service.get({},'','').then(function(serviceResponse) {
actualX = serviceResponse.x;
};
$rootScope.$apply(); // that will actually resolve the promise
expect(actualX).toEqual(_fakeServerResponse.x);
}));
Upvotes: 1