mercredi 5 décembre 2018

how to resolve Promise{$$state: Object{status: 0}}

I am testing a controller that uses a service that returns a promise. I need to resolve promise. I am using Jasmine 2.

Here is Spec code

beforeEach(inject(function ($controller, $rootScope, myService, $q, $rootScope, $httpBackend) {

 scope = $rootScope.$new();
 $q = _$q_;
 $httpBackend = _$httpBackend_;
 $rootScope = _$rootScope_;
 myService = _myService_;
 ctrl =  $controller('Ctrl', { '$scope': scope, 'myService': myService });

}));

it('getDateRangeData return Data obj', function() {

  var value
  var testnew = spyOn(myService, 'getDateRangeData').and.callThrough();
 var dateee = dateRange = myService.getDateRange();
  console.log("dateee", dateee);

 var test = myService.getDateRangeData(dateRange).then(function(value){

   expect(response).toBe(true);

 }, function() {
  console.log("error on request");
 });

});

test variable returns {$$state: Object{status: 0}} . I need to resolve the promise and write test case for data return true

Aucun commentaire:

Enregistrer un commentaire