I'm working on a very old project with the following frameworks for unit testing: QUnit 1.14.0, Sinon 1.17.2, jQuery 1.12.4
This unit test works fine with jQuery 1.x and 2.x. But after upgrading to 3.x, I got error requests[1] is undefined, which means the second AJAX call is not caught. I read the 3.0 doc and it seems 3.0 has a new version of Deferred which was changed to behave like the native Promise object. But I'm not sure how that could screw up the tests.
function doSomething(successCallback, failureCallback) {
var promise = firstCall()
.then(secondCall);
if (successCallback) {
promise.done(successCallback);
}
if (failureCallback) {
promise.fail(failureCallback);
}
return promise;
}
function firstCall() {
return $.ajax({
url: 'No1.aspx',
type: 'HEAD'
});
}
function secondCall() {
return $.ajax({
url: 'No2.aspx',
type: 'GET'
});
}
QUnit.test('correct sequence of AJAX calls', function (assert) {
var server = this.sandbox.useFakeServer();
doSoemthing(this.successHandler, this.failureHandler);
// Simulate successful responses to the two expected AJAX requests
server.requests[0].respond('success');
server.requests[1].respond('success');
assert.equal( 1, "1", "dummy" );
});