× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

unit testing angularjs $q.all - promise never completes

Dean Sofer
Jun 13, 2015
<p><code>afterEach()</code> is used for cleanup, not for executing code after your preparations but before your tests. <code>$scope.$apply()</code> is not cleanup either.</p> <p>You need to be doing the following:</p> <pre><code>// setup async behavior var all = $q.all(x.promise, y.promise) // resolve your deferreds/promises x.reject(); y.reject(); // call $scope.$apply() to 'digest' all the promises $scope.$apply(); // test the results return all.should.be.rejected; </code></pre> <p>You're doing an <code>$apply()</code> AFTER your tests are done, not in between setup and evaluation.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/26751846/unit%20testing%20angularjs%20%24q.all%20-%20promise%20never%20completes/26826037">Stack Overflow</a>.</p>
comments powered by Disqus