Clearing request headers on fakeRequest.open()

https://github.com/jasmine/jasmine-ajax/issues/142
This commit is contained in:
Christopher Rock 2016-01-19 22:01:43 -05:00
parent 920f8e7771
commit ca2ee0202a
3 changed files with 16 additions and 0 deletions

View File

@ -278,6 +278,7 @@ getJasmineRequireObj().AjaxFakeRequest = function(eventBusFactory) {
this.username = arguments[3];
this.password = arguments[4];
this.readyState = 1;
this.requestHeaders = {};
this.eventBus.trigger('readystatechange');
},

View File

@ -98,6 +98,20 @@ describe('FakeRequest', function() {
expect(request.contentType()).toEqual('application/text+xml');
});
it('clears the request headers when opened', function() {
// Requirement #14 https://www.w3.org/TR/XMLHttpRequest/#the-open()-method
var request = new this.FakeRequest();
request.setRequestHeader('X-Header1', 'value1');
expect(request.requestHeaders['X-Header1']).toEqual('value1');
request.open();
expect(request.requestHeaders['X-Header1']).not.toBeDefined();
expect(request.requestHeaders).toEqual({});
});
describe('managing readyState', function() {
beforeEach(function() {
this.request = new this.FakeRequest();

View File

@ -116,6 +116,7 @@ getJasmineRequireObj().AjaxFakeRequest = function(eventBusFactory) {
this.username = arguments[3];
this.password = arguments[4];
this.readyState = 1;
this.requestHeaders = {};
this.eventBus.trigger('readystatechange');
},