title: How to write a unit test with Jest for code with Promise
body: <p>I am trying to write a unit test with Jest and Jasmine-pit for the below code and am totally stumped with it. The code is an ajax call which retrieves some data from resource and saves it in the variable.  </p>
  
  <pre><code>init = function() {
      var deferred = Q.defer();
      $.ajax({
          type: 'GET',
          datatype: 'json',
          url: window.location.origin + name,
          success: function (data) {
              userId = data.userId;
              apiKey = data.apiKey;
              deferred.resolve();
          }
      });
      return deferred.promise;
  },
  </code></pre>