Q:

$q deferred not firing continuations in Jasmine

I am creating some unit tests that work with promises which I want to resolve manually and am finding that my promise continuations seem never to be hit. So I open up the console in my jasmine debug panel, put a reference to $q on the window object...and
d = $q.defer()
d.promise.then(x => console.log(`done`, x))
d.resolve(5)

Nothing gets logged...

What is going on?! Is $q somehow now working? Does it not work like every other deferred implementation in the world works? Am I reading their (insanely meager) documentation wrong? How is it possible for the above promise to be resolved but not have its continuation fire?!
AngularJs 1.5.8

A:

Logs "done 5" in this example

angular.module("app",[])
.run(function($q) {
   var d = $q.defer();
   d.promise.then(x => console.log(`done`, x));
   d.resolve(5);
});
<script src="//unpkg.com/angular/angular.js"></script>
  <body ng-app="app">
    <h1>Promise example</h1>
  </body>

Integration with the browser event loop
AngularJS modifies the normal JavaScript flow by providing its own event processing loop. This splits the JavaScript into classical and AngularJS execution context. Use $apply() to enter the AngularJS execution context from JavaScript. Keep in mind that in most places (controllers, services) $apply has already been called for you by the directive which is handling the event.

ES6 promises are handled by the JavaScript event loop. $q promises are handled by the AngularJS event loop. Only operations which are applied in the AngularJS execution context will benefit from AngularJS data-binding, exception handling, property watching, etc.
In the case of Jasmine tests, use $rootScope.$apply() to enter the AngularJS execution context.
For more information, see AngularJS Developer Guide - Integration with the browser event loop

