I am trying to stub a method using sinon, jasmine and $q. I want that method to return my fake data.
The problem is that the defined then
statement is never called and i can not figure out why.
This already is a simplified version but it still isn't working:
- The stub is called
- The console log
Steven Stub is called
gets called - None of the
then
callbacks are 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?