javascript - Jasmine async test using promises -
javascript - Jasmine async test using promises -
i doing jasmine testing using angular promises , have question related timing. found reply here unit-test promise-based code in angular, need clarification how works. given then
method handled in asynchronous way how next test guaranteed pass. isn't there risk expect
run ahead of then
block beingness executed , run expect before value has been assigned. or... digest cycle guarantee value assigned before expect runs. meaning, digest cycle behave blocking phone call guarantees promises resolved before code allowed proceed.
function someservice(){ var deferred = $q.defer(); deferred.resolve(myobj); homecoming deferred.promise; } ('testing promise', function() { var res; var res2; someservice().then(function(obj){ res = "test"; }); someservice().then(function(obj){ res2 = "test2"; }); $rootscope.$apply(); expect(res).tobe('test'); expect(res2).tobe('test2'); });
a digest cycle behave blocking phone call guarantees promises resolved before code allowed proceed.
yes, although more accurately guarantee success callbacks of resolved promises have run.
there similar example shows how digest cycle tied success callbacks of promises in docs $q
javascript angularjs unit-testing jasmine
Comments
Post a Comment