Search Posts

Category: q

Why does a failed assertion trigger a promise catch?

While writing unit tests for an angular app I was experiencing unexpected results. I was able to condense the unexpected behavior into a sample test. The should.equal(true, false, ‘should then’) assertion failure in the then block seems to trigger the catch block of the promise. describe.only(‘test’, function () { var $q, $rootScope; beforeEach(function () { inject(function(_$q_, _$rootScope_) { $q = _$q_; $rootScope = _$rootScope_.$new(); }); }); var stubService = sinon.stub(service, ‘getPanel’); it(‘shall…’, function() { //1 […]

loop until promise function give result

I’m looking to loop on a promise function until I have the result I want. As of now I’m using recursivity like this: function pull() { dataFactory.pullFunction().then(function(res) { pull() }) } But that’s giving me some front-end/style bugs for my loading bar for example. I would do something like this: function pull() { while (res.status == ‘ONGOING’) { dataFactory.pullFunction().then(function(res) { // my stuffs }) } } But when I try it the pullFunction() is never […]