I can fake ajax with both of these tools. Sinon allow to create stub/spy/mock that come handy for testing and mockjax doesn't. When it come to faking ajax call, does mockjax provide more features then Sinon? Cause if it doesn't, there is no point is using both of them.
var response = [];
var statusCode = 200;
var responseTime = 0;
Example how to fake ajax call with mockjax :
$.mockjax({
url: server_api_url + "/Something/GetData",
status: statusCode,
responseTime: responseTime,
contentType: "application/json",
responseText: response
});
Example how to fake ajax call with Sinon.js :
var def = $.Deferred();
var stubGetData = sinon.stub(serverApiForSomething, "GetData");
def.resolve(response);
stubGetData.returns(def);
Where serverApiForSomething is a global class that encapsulate ajax call.
ServerApiForSomething = function()
{
var self = this;
self.GetData = function(param)
{
var ajaxOption =
{
url:server_Api_Url + "/Something/GetData",
type: "GET",
data: { param.toJSON() },
contentType: "application/json",
dataType: "json"
}
return $.ajax(ajaxOption);
}
}
serverApiForSomething = new ServerApiForSomething();
Draft answer
While both can fake ajax call, mockjax provide more build-in feature. However, those feature are really about "ajax call" and are quite too much if you only need to fake ajax call with basic "succeeded"/"failed" behaviour.
For example, with mockjax, you can
See mockjax documentation here
With mockjax you can also find all ajax call that were made without being faked. This is really usefull.
So, unless you need to fake more then failure/success and the value returned, sinon is quite enough and easier to use as you don't need to bother with route and other related stuff.