Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support for simulating timeout with responseTimeout

  • Loading branch information...
commit 9286df30e4b264a4fb11fdc932052277d0b0bda0 1 parent 0c0f5a5
@rdy rdy authored
Showing with 36 additions and 1 deletion.
  1. +1 −1  lib/mock-ajax.js
  2. +35 −0 spec/javascripts/mock-ajax-jquery-spec.js
View
2  lib/mock-ajax.js
@@ -106,7 +106,7 @@ function FakeXMLHttpRequest() {
},
responseTimeout: function() {
xhr.readyState = 4;
- jasmine.Clock.tick($.ajaxSettings.timeout || 30000);
+ jasmine.Clock.tick(jQuery.ajaxSettings.timeout || 30000);
xhr.onreadystatechange('timeout');
}
};
View
35 spec/javascripts/mock-ajax-jquery-spec.js
@@ -286,6 +286,41 @@ describe("Jasmine Mock Ajax (for jQuery)", function() {
sharedAjaxResponseBehaviorForJQuery_Failure(sharedContext);
});
+
+ describe('when simulating a response with request.responseTimeout', function() {
+ beforeEach(function() {
+ jasmine.Clock.useMock();
+
+ jQuery.ajax({
+ url: "example.com/someApi",
+ type: "GET",
+ dataType: "text",
+ success: success,
+ complete: complete,
+ error: error
+ });
+ request = mostRecentAjaxRequest();
+ response = {contentType: "text/html", responseText: "(._){"};
+ request.responseTimeout(response);
+
+ sharedContext.responseCallback = error;
+ sharedContext.status = response.status;
+ sharedContext.contentType = response.contentType;
+ sharedContext.responseText = response.responseText;
+ });
+
+ it("should not call the success handler", function() {
+ expect(success).not.toHaveBeenCalled();
+ });
+
+ it("should call the failure handler", function() {
+ expect(error).toHaveBeenCalled();
+ });
+
+ it("should call the complete handler", function() {
+ expect(complete).toHaveBeenCalled();
+ });
+ });
});
Please sign in to comment.
Something went wrong with that request. Please try again.