An issue arises when attempting to test the code below using Jasmine, as the console.log in `then` is never called. The question remains: is this problem related to Angular or Jasmine?
describe("angular test", function() {
var $q;
beforeEach(function() {
angular.mock.inject(function getDependencies(_$q_) {
$q = _$q_;
});
});
it("angular nested promise with jasmine", function(done) {
$q(function(resolve, reject) {
resolve(10);
})
.then(function(r) {
console.log(r);
})
.finally(function() {
done();
});
});
})
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine-html.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/boot.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="https://code.angularjs.org/1.4.5/angular-mocks.js"></script>
Special thanks to Merott for providing the solution.
Next inquiry:
When testing a service that returns a promise which is wrapped within the service, including a digest is necessary. But, is the digest required solely for Jasmine or even in usual cases (meaning for the service)?