title: How can I tell if an object is an Angular $q promise?
body: <p>I have a pre-existing non-Angular API library in my project. It has a <code>.request</code> method which returns jQuery.Deferred promises. I created a simple Angular service which wraps the <code>.request</code> method to transform its result into an Angular $q promise instead. It looks something like this:</p>
  
  <pre class="lang-javascript prettyprint-override"><code>var module = angular.module('example.api', []);
  
  module.factory('api', function(
      $q,
      $window
  ) {
      function wrappedRequest() {
          var result = $window.API.request.apply($window.API, arguments);
          return $q.when(result);
      };
  
      return {
          request: wrappedRequest
      };
  });
  </code></pre>
  
  <p>I would like to write a test which ensures that this service is functioning correctly. It will provide a mock <code>$window</code> with an <code>API</code> whose <code>request</code> method returns jQuery.Deferred promises. I need to ensure that the resulting objects are Angular $q promises.</p>
  
  <hr>
  
  <p>How can I determine whether an object is an Angular $q promise?</p>
  
  <p>For the example given in this question it would be sufficient to distinguish between jQuery.Deferred promises and Angular $q promises, but ideally we could identify Angular $q promises in general.</p>