That method of permitted promises is not called

I am trying to stub a method using sinon, jasmine and $ q. I want this method to return my fake data.

The problem is that a certain operator is thennever called, and I cannot understand why. This is a simplified version, but it still does not work:

  • The title page is called
  • Console log Steven Stub is calledreceives a call
  • None of the callbacks thenare called.
  • No error message

Here is my code

var p = {steven: function() {console.log('original steven');}},
    pStub = sinon.stub(p, 'steven', function(){
      console.log('Steven Stub is called');
      var defer = $q.defer();
      defer.resolve({item: 5});
      return defer.promise;
});

var promise = p.steven();

promise.then(
  function(data){console.log('Peter?');},
  function(data) {console.log('ERROR?');},
  function(data) {console.log('progress?');});

Any idea?

+4
source share
1 answer

, . Angular 2.0 , ( Angular 1.2 , Angular 1.1),

$rootScope.$digest()

promises. , promises evalAsync. . , , $q promises.

+8

Source: https://habr.com/ru/post/1540215/


All Articles