title: How to properly unit test jQuery's .ajax() promises using Jasmine and/or Sinon?
body: <p>I've got a fairly straightforward function which returns a jQuery .ajax() promise as such:</p>
  
  <pre><code>CLAW.controls.validateLocation = function(val, $inputEl) {
      return $.ajax({
          url: locationServiceUrl + 'ValidateLocation/',
          data: {
              'locationName': val
          },
          beforeSend: function() {
              $inputEl.addClass('busy');
          }
      }).done(function(result) {
          // some success clauses
      }).fail(function(result) {
          // some failure clauses
      }).always(function() {
          // some always clauses
      });
  }
  </code></pre>
  
  <p>For the most part, this new promises interface works like a dream, and eliminating callback pyramids when using jQuery's .ajax() is great. However, I cannot for the life of me figure out how to properly test these promises using Jasmine and/or Sinon:</p>
  
  <ol>
  <li><p>All of Sinon's documentation assumes you're using old-school
  callbacks; I don't see a single example of how to use it with
  promises/deferreds</p></li>
  <li><p>When attempting to use a Jasmine or Sinon spy to spy on $.ajax, the
  spy is effectively overwriting the promise, so its <code>done</code>, <code>fail</code>,
  and <code>always</code> clauses no longer exist on the ajax function, so the promise never resolves and tosses an error instead</p></li>
  </ol>
  
  <p>I'd really just love an example or two of how to test these new jQuery .ajax() promises with the aforementioned testing libs. I've scoured the 'net fairly intensely and haven't really dredged up anything on doing so. The one resource I did find mentioned using Jasmine.ajax, but I'd like to avoid that if possible, seeing as Sinon provides most of the same capabilities out-of-the-box.</p>