diff --git a/lib/sinon/util/fake_xml_http_request.js b/lib/sinon/util/fake_xml_http_request.js index c476aff38..ff4905178 100644 --- a/lib/sinon/util/fake_xml_http_request.js +++ b/lib/sinon/util/fake_xml_http_request.js @@ -654,13 +654,16 @@ extend(FakeXMLHttpRequest.prototype, sinonEvent.EventTarget, { } }); -extend(FakeXMLHttpRequest, { +var states = { UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4 -}); +}; + +extend(FakeXMLHttpRequest, states); +extend(FakeXMLHttpRequest.prototype, states); function useFakeXMLHttpRequest() { FakeXMLHttpRequest.restore = function restore(keepOnCreate) { diff --git a/test/util/fake-xml-http-request-test.js b/test/util/fake-xml-http-request-test.js index da378556f..f0d130fd8 100644 --- a/test/util/fake-xml-http-request-test.js +++ b/test/util/fake-xml-http-request-test.js @@ -132,13 +132,22 @@ if (typeof window !== "undefined") { assert.same(FakeXMLHttpRequest.prototype.constructor, FakeXMLHttpRequest); }); - it("implements readyState constants", function () { + it("class implements readyState constants", function () { assert.same(FakeXMLHttpRequest.OPENED, 1); assert.same(FakeXMLHttpRequest.HEADERS_RECEIVED, 2); assert.same(FakeXMLHttpRequest.LOADING, 3); assert.same(FakeXMLHttpRequest.DONE, 4); }); + it("instance implements readyState constants", function () { + var xhr = new FakeXMLHttpRequest(); + + assert.same(xhr.OPENED, 1); + assert.same(xhr.HEADERS_RECEIVED, 2); + assert.same(xhr.LOADING, 3); + assert.same(xhr.DONE, 4); + }); + it("calls onCreate if listener is set", function () { var onCreate = sinonSpy(); FakeXMLHttpRequest.onCreate = onCreate;