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?
source
share