Rotem B Rotem B - 9 months ago 82
AngularJS Question

Jasmine spec has no expectation

I have the following code:

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) {

and the get method:


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).



$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