Create requestHeaders object in FakeXMLHttpRequest constructor instead of on the prototype
This commit is contained in:
parent
b0d4d0d573
commit
c788f13224
@ -98,12 +98,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
function fakeRequest(requestTracker, stubTracker) {
|
||||
function FakeXMLHttpRequest() {
|
||||
requestTracker.track(this);
|
||||
this.requestHeaders = {};
|
||||
}
|
||||
|
||||
extend(FakeXMLHttpRequest.prototype, window.XMLHttpRequest);
|
||||
extend(FakeXMLHttpRequest.prototype, {
|
||||
requestHeaders: {},
|
||||
|
||||
open: function() {
|
||||
this.method = arguments[0];
|
||||
this.url = arguments[1];
|
||||
|
@ -1,17 +1,46 @@
|
||||
describe("FakeXMLHttpRequest", function() {
|
||||
var xhr;
|
||||
var xhr2;
|
||||
beforeEach(function() {
|
||||
var realXMLHttpRequest = jasmine.createSpy('realRequest'),
|
||||
fakeGlobal = {XMLHttpRequest: realXMLHttpRequest},
|
||||
mockAjax = new MockAjax(fakeGlobal);
|
||||
mockAjax.install();
|
||||
xhr = new fakeGlobal.XMLHttpRequest();
|
||||
xhr2 = new fakeGlobal.XMLHttpRequest();
|
||||
});
|
||||
|
||||
it("should have an initial readyState of 0 (uninitialized)", function() {
|
||||
expect(xhr.readyState).toEqual(0);
|
||||
});
|
||||
|
||||
describe("when setting request headers", function() {
|
||||
beforeEach(function() {
|
||||
xhr.setRequestHeader('X-Header-1', 'one');
|
||||
});
|
||||
|
||||
it("should make the request headers available", function() {
|
||||
expect(Object.keys(xhr.requestHeaders).length).toEqual(1);
|
||||
expect(xhr.requestHeaders['X-Header-1']).toEqual('one');
|
||||
});
|
||||
|
||||
describe("when setting headers on another xhr object", function() {
|
||||
beforeEach(function() {
|
||||
xhr2.setRequestHeader('X-Header-2', 'two');
|
||||
});
|
||||
|
||||
it("should make the only its request headers available", function() {
|
||||
expect(Object.keys(xhr2.requestHeaders).length).toEqual(1);
|
||||
expect(xhr2.requestHeaders['X-Header-2']).toEqual('two');
|
||||
});
|
||||
|
||||
it("should not modify any other xhr objects", function() {
|
||||
expect(Object.keys(xhr.requestHeaders).length).toEqual(1);
|
||||
expect(xhr.requestHeaders['X-Header-1']).toEqual('one');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when opened", function() {
|
||||
beforeEach(function() {
|
||||
xhr.open("GET", "http://example.com");
|
||||
|
Loading…
Reference in New Issue
Block a user