Skip to content
This repository

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

Merged
merged 1 commit into from about 2 years ago

2 participants

Max Lynch Jonathan Sharp
Max Lynch

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.

Max Lynch 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
Jonathan Sharp jdsharp merged commit b6b5cda into from April 10, 2012
Jonathan Sharp jdsharp closed this April 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 10, 2012
Max Lynch 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
This page is out of date. Refresh to see the latest.
13  jquery.mockjax.js
@@ -171,15 +171,14 @@
171 171
 						this.statusText = mockHandler.statusText;
172 172
 					}
173 173
 					// jQuery < 1.4 doesn't have onreadystate change for xhr
174  
-					if ( $.isFunction(this.onreadystatechange) && !mockHandler.isTimeout ) {
  174
+					if ( $.isFunction(this.onreadystatechange) ) {
  175
+						if( mockHandler.isTimeout) {
  176
+							this.status = -1;
  177
+						}
175 178
 						this.onreadystatechange( mockHandler.isTimeout ? 'timeout' : undefined );
176 179
 					} else if ( mockHandler.isTimeout ) {
177  
-						if ( $.isFunction( $.handleError ) ) {
178  
-							// Fix for 1.3.2 timeout to keep success from firing.
179  
-							this.readyState = -1;
180  
-						}
181  
-						requestSettings.error( this, "timeout" );
182  
-						requestSettings.complete( this, "timeout" );
  180
+						// Fix for 1.3.2 timeout to keep success from firing.
  181
+						this.status = -1;
183 182
 					}
184 183
 				}).apply(that);
185 184
 			};
48  test/test.js
@@ -844,31 +844,33 @@ asyncTest('Forcing timeout', function() {
844 844
 	$.mockjaxClear();
845 845
 });
846 846
 // FORCE SIMULATION OF SERVER TIMEOUTS WITH PROMISES
847  
-asyncTest('Forcing timeout with Promises', function() {
848  
-	$.mockjax({
849  
-		url: '/response-callback',
850  
-		responseText: 'done',
851  
-		isTimeout: true
852  
-	});
853 847
 
854  
-	var request = $.ajax({
855  
-		url: '/response-callback'
856  
-	});
  848
+if(jQuery.Deferred) {
  849
+	asyncTest('Forcing timeout with Promises', function() {
  850
+		$.mockjax({
  851
+			url: '/response-callback',
  852
+			isTimeout: true,
  853
+		});
857 854
 
858  
-    request.done(function(xhr) {
859  
-        ok(true, "error callback was called");
860  
-    });
861  
-    
862  
-    request.fail(function(response) {
863  
-        ok(false, "should not be be successful");
864  
-    });
865  
-    
866  
-    request.always(function(xhr) {
867  
-        start();
868  
-    });
869  
-    
870  
-	$.mockjaxClear();
871  
-});
  855
+		var request = $.ajax({
  856
+			url: '/response-callback'
  857
+		});
  858
+
  859
+		request.done(function(xhr) {
  860
+			ok(false, "Should not be successful");
  861
+		});
  862
+
  863
+		request.fail(function(response) {
  864
+			ok(true, "error callback was called");
  865
+		});
  866
+
  867
+		request.complete(function(xhr) {
  868
+			start();
  869
+		});
  870
+
  871
+		$.mockjaxClear();
  872
+	});
  873
+}
872 874
 // DYNAMICALLY GENERATING MOCK DEFINITIONS
873 875
 asyncTest('Dynamic mock definition', function() {
874 876
 	$.mockjax( function( settings ) {
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.