trigger onreadystatechange everywhere we set readyState
- Partially addresses #19
This commit is contained in:
parent
ca0acd7109
commit
3ebf994356
@ -109,6 +109,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
this.username = arguments[3];
|
||||
this.password = arguments[4];
|
||||
this.readyState = 1;
|
||||
this.onreadystatechange();
|
||||
},
|
||||
|
||||
setRequestHeader: function(header, value) {
|
||||
@ -119,6 +120,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
this.readyState = 0;
|
||||
this.status = 0;
|
||||
this.statusText = "abort";
|
||||
this.onreadystatechange();
|
||||
},
|
||||
|
||||
readyState: 0,
|
||||
@ -134,6 +136,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
send: function(data) {
|
||||
this.params = data;
|
||||
this.readyState = 2;
|
||||
this.onreadystatechange();
|
||||
|
||||
var stub = stubTracker.findStub(this.url);
|
||||
if (stub) {
|
||||
|
@ -43,30 +43,39 @@ describe("FakeXMLHttpRequest", function() {
|
||||
|
||||
describe("when opened", function() {
|
||||
beforeEach(function() {
|
||||
spyOn(xhr, 'onreadystatechange');
|
||||
xhr.open("GET", "http://example.com");
|
||||
});
|
||||
|
||||
it("should have a readyState of 1 (open)", function() {
|
||||
expect(xhr.readyState).toEqual(1);
|
||||
expect(xhr.onreadystatechange).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("when sent", function() {
|
||||
it("should have a readyState of 2 (sent)", function() {
|
||||
xhr.onreadystatechange.calls.reset();
|
||||
xhr.send(null);
|
||||
expect(xhr.readyState).toEqual(2);
|
||||
expect(xhr.onreadystatechange).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when a response comes in", function() {
|
||||
it("should have a readyState of 4 (loaded)", function() {
|
||||
xhr.onreadystatechange.calls.reset();
|
||||
xhr.response({status: 200});
|
||||
expect(xhr.readyState).toEqual(4);
|
||||
expect(xhr.onreadystatechange).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when aborted", function() {
|
||||
it("should have a readyState of 0 (uninitialized)", function() {
|
||||
xhr.onreadystatechange.calls.reset();
|
||||
xhr.abort();
|
||||
expect(xhr.readyState).toEqual(0);
|
||||
expect(xhr.onreadystatechange).toHaveBeenCalled();
|
||||
expect(xhr.status).toEqual(0);
|
||||
expect(xhr.statusText).toEqual("abort");
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user