Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed isTimeout issue for deferred-style ajax requests. Fixes #63 #65

Merged
merged 1 commit into from

2 participants

@mlynch

This fix also changes some of the behavior of timeouts, namely it no longer manually calls error or complete on timeout. Instead, it lets jQuery handle that, as it should.

Also changes some spaces to tabs in the original pull request.

@mlynch mlynch Fixed isTimeout issue for deferred-style ajax requests. Fixes #63
This fix also changes some of the behavior of timeouts, namely it no
longer manually calls error or complete on timeout. Instead, it lets
jQuery handle that, as it should.
b0b29d9
@jdsharp jdsharp merged commit b6b5cda into jakerella:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 10, 2012
  1. @mlynch

    Fixed isTimeout issue for deferred-style ajax requests. Fixes #63

    mlynch authored
    This fix also changes some of the behavior of timeouts, namely it no
    longer manually calls error or complete on timeout. Instead, it lets
    jQuery handle that, as it should.
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 30 deletions.
  1. +6 −7 jquery.mockjax.js
  2. +25 −23 test/test.js
View
13 jquery.mockjax.js
@@ -171,15 +171,14 @@
this.statusText = mockHandler.statusText;
}
// jQuery < 1.4 doesn't have onreadystate change for xhr
- if ( $.isFunction(this.onreadystatechange) && !mockHandler.isTimeout ) {
+ if ( $.isFunction(this.onreadystatechange) ) {
+ if( mockHandler.isTimeout) {
+ this.status = -1;
+ }
this.onreadystatechange( mockHandler.isTimeout ? 'timeout' : undefined );
} else if ( mockHandler.isTimeout ) {
- if ( $.isFunction( $.handleError ) ) {
- // Fix for 1.3.2 timeout to keep success from firing.
- this.readyState = -1;
- }
- requestSettings.error( this, "timeout" );
- requestSettings.complete( this, "timeout" );
+ // Fix for 1.3.2 timeout to keep success from firing.
+ this.status = -1;
}
}).apply(that);
};
View
48 test/test.js
@@ -844,31 +844,33 @@ asyncTest('Forcing timeout', function() {
$.mockjaxClear();
});
// FORCE SIMULATION OF SERVER TIMEOUTS WITH PROMISES
-asyncTest('Forcing timeout with Promises', function() {
- $.mockjax({
- url: '/response-callback',
- responseText: 'done',
- isTimeout: true
- });
- var request = $.ajax({
- url: '/response-callback'
- });
+if(jQuery.Deferred) {
+ asyncTest('Forcing timeout with Promises', function() {
+ $.mockjax({
+ url: '/response-callback',
+ isTimeout: true,
+ });
- request.done(function(xhr) {
- ok(true, "error callback was called");
- });
-
- request.fail(function(response) {
- ok(false, "should not be be successful");
- });
-
- request.always(function(xhr) {
- start();
- });
-
- $.mockjaxClear();
-});
+ var request = $.ajax({
+ url: '/response-callback'
+ });
+
+ request.done(function(xhr) {
+ ok(false, "Should not be successful");
+ });
+
+ request.fail(function(response) {
+ ok(true, "error callback was called");
+ });
+
+ request.complete(function(xhr) {
+ start();
+ });
+
+ $.mockjaxClear();
+ });
+}
// DYNAMICALLY GENERATING MOCK DEFINITIONS
asyncTest('Dynamic mock definition', function() {
$.mockjax( function( settings ) {
Something went wrong with that request. Please try again.