Added readyState changes to FakeXmlHttpRequest.

Took out rogue console.error.
This commit is contained in:
Austin Putman & Sarah Mei 2010-09-28 11:41:50 -07:00
parent ec1867e944
commit a4d3881e7e
3 changed files with 44 additions and 1 deletions

View File

@ -21,6 +21,7 @@ function FakeXMLHttpRequest() {
open: function() {
xhr.method = arguments[0];
xhr.url = arguments[1];
xhr.readyState = 1;
},
setRequestHeader: function(header, value) {
@ -28,14 +29,19 @@ function FakeXMLHttpRequest() {
},
abort: function() {
xhr.readyState = 0;
},
readyState: 0,
onreadystatechange: function() {
},
status: null,
send: function(data) {
xhr.params = data;
xhr.readyState = 2;
},
getResponseHeader: function(name) {

View File

@ -0,0 +1,38 @@
describe("FakeXMLHttpRequest", function() {
var xhr;
beforeEach(function() {
xhr = new FakeXMLHttpRequest();
});
it("should have an initial readyState of 0 (uninitialized)", function() {
expect(xhr.readyState).toEqual(0);
});
describe("when opened", function() {
beforeEach(function() {
xhr.open("GET", "http://example.com")
});
it("should have a readyState of 1 (open)", function() {
expect(xhr.readyState).toEqual(1);
});
describe("when sent", function() {
it("should have a readyState of 2 (sent)", function() {
xhr.send(null);
expect(xhr.readyState).toEqual(2);
});
});
describe("when a response comes in", function() {
it("should have a readyState of 4 (loaded)", function() {
xhr.response({status: 200});
expect(xhr.readyState).toEqual(4);
});
});
describe("when aborted", function() {
it("should have a readyState of 0 (uninitialized)", function() {
xhr.abort();
expect(xhr.readyState).toEqual(0);
});
});
});
});

View File

@ -311,7 +311,6 @@ function sharedAjaxResponseBehaviorForJQuery_Failure(context) {
var xhr;
beforeEach(function() {
xhr = context.responseCallback.mostRecentCall.args[0];
console.error("=============> xhr: ", xhr);
});
it("should have the expected status code", function() {