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();