I have a pretty simple function that returns jQuery.ajax () as such:
CLAW.controls.validateLocation = function(val, $inputEl) { return $.ajax({ url: locationServiceUrl + 'ValidateLocation/', data: { 'locationName': val }, beforeSend: function() { $inputEl.addClass('busy'); } }).done(function(result) {
For the most part, this new promises interface works like a dream and eliminates callback pyramids when using jQuery.ajax () perfectly. However, I cannot understand for life how to properly test these promises using Jasmine and / or Sinon:
All Sinon documentation assumes that you are using an old school callbacks; I do not see any example of how to use it with promises / deferreds
When trying to use Jasmine or Sinon spying to spy on $ .ajax, the spy effectively rewrites the promise, so its done , fail , and always no longer exists in the ajax function, so the promise never resolves and throws an error instead
I would really like an example or two of how to check out these new jQuery.ajax () promises with the above test libraries. I was pretty much looking for a "network" and actually did nothing. One resource I found is mentioned using Jasmine.ajax, but I would like to avoid this if possible, because Sinon provides most of the same features out of the box.
jquery unit-testing jasmine sinon
J. Ky Marsh Oct 30 '12 at 22:15 2012-10-30 22:15
source share