javascript - Chaining function that returns promise doesn't resolve after flushing timeout -
javascript - Chaining function that returns promise doesn't resolve after flushing timeout -
the chain within testcode not resolve... resolve level 1 , level2.
it('three level promise', inject(function ($q, $timeout, $rootscope) { var plusone = function(value) { var deferred = $q.defer(); $timeout(function() { deferred.resolve(value+1); }, 10); homecoming deferred.promise; } var promisecall = function() { homecoming plusone(1).then(function (data){ console.error('call1 resolved', data); homecoming plusone(data).then(function (data2){ console.error('call2 resolved', data2); homecoming plusone(data2).then(function (data3){ console.error('call3 resolved', data3); homecoming data3; }); }); }); } var result; promisecall().then(function (data) { result = data; }); $timeout.flush(); // forcefulness timeout flushed. expect(result).tobe(3); }));
i cant see why shouldnt work... :-(
... , stackoverflow dont have much code within request.
two problems:
$timeout.flush();
flushes first $timeout
call. other 2 haven't been called @ point. have phone call $timeout.flush();
3 times, not once.
second: expected result not 3, 4. start 1 , resolved value +1. resolve 3 times.
javascript angularjs promise angular-promise
Comments
Post a Comment