From 2d0bf42151e70f4c11d45fe2eefe9dbf98125819 Mon Sep 17 00:00:00 2001 From: slackersoft Date: Fri, 23 Jan 2015 13:11:42 -0800 Subject: [PATCH] Include trailing newline in response headers to match browsers. - Some libraries are relying on it existing, even though the specs doesn't say it should. Fix #91 --- lib/mock-ajax.js | 2 +- spec/fakeRequestSpec.js | 10 +++++----- spec/mock-ajax-toplevel-spec.js | 4 ++-- src/fakeRequest.js | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/mock-ajax.js b/lib/mock-ajax.js index bef9ab7..a8367a5 100644 --- a/lib/mock-ajax.js +++ b/lib/mock-ajax.js @@ -257,7 +257,7 @@ getJasmineRequireObj().AjaxFakeRequest = function() { responseHeaders.push(this.responseHeaders[i].name + ': ' + this.responseHeaders[i].value); } - return responseHeaders.join('\r\n'); + return responseHeaders.join('\r\n') + '\r\n'; }, responseText: null, diff --git a/spec/fakeRequestSpec.js b/spec/fakeRequestSpec.js index 4b7b4c8..f7998c5 100644 --- a/spec/fakeRequestSpec.js +++ b/spec/fakeRequestSpec.js @@ -535,8 +535,8 @@ describe('FakeRequest', function() { request1.respondWith({ status: 200, responseHeaders: { 'X-Foo': 'bar' } }); request2.respondWith({ status: 200, responseHeaders: { 'X-Baz': 'quux' } }); - expect(request1.getAllResponseHeaders()).toBe('X-Foo: bar'); - expect(request2.getAllResponseHeaders()).toBe('X-Baz: quux'); + expect(request1.getAllResponseHeaders()).toBe("X-Foo: bar\r\n"); + expect(request2.getAllResponseHeaders()).toBe("X-Baz: quux\r\n"); }); it('retrieves all response headers', function() { @@ -553,7 +553,7 @@ describe('FakeRequest', function() { ] }); - expect(request.getAllResponseHeaders()).toBe("X-Header-1: foo\r\nX-Header-2: bar\r\nX-Header-1: baz"); + expect(request.getAllResponseHeaders()).toBe("X-Header-1: foo\r\nX-Header-2: bar\r\nX-Header-1: baz\r\n"); }); it('sets the content-type header to the specified contentType when no other headers are supplied', function() { @@ -564,7 +564,7 @@ describe('FakeRequest', function() { request.respondWith({ status: 200, contentType: 'text/plain' }); expect(request.getResponseHeader('content-type')).toBe('text/plain'); - expect(request.getAllResponseHeaders()).toBe('Content-Type: text/plain'); + expect(request.getAllResponseHeaders()).toBe("Content-Type: text/plain\r\n"); }); it('sets a default content-type header if no contentType and headers are supplied', function() { @@ -575,7 +575,7 @@ describe('FakeRequest', function() { request.respondWith({ status: 200 }); expect(request.getResponseHeader('content-type')).toBe('application/json'); - expect(request.getAllResponseHeaders()).toBe('Content-Type: application/json'); + expect(request.getAllResponseHeaders()).toBe("Content-Type: application/json\r\n"); }); it('has no responseXML by default', function() { diff --git a/spec/mock-ajax-toplevel-spec.js b/spec/mock-ajax-toplevel-spec.js index b88f65e..6b01761 100644 --- a/spec/mock-ajax-toplevel-spec.js +++ b/spec/mock-ajax-toplevel-spec.js @@ -267,7 +267,7 @@ describe("Jasmine Mock Ajax (for toplevel)", function() { "X-Header1: header 1 value", "X-Header2: header 2 value", "X-Header3: header 3 value" - ].join("\r\n")); + ].join("\r\n") + "\r\n"); }); }); @@ -295,7 +295,7 @@ describe("Jasmine Mock Ajax (for toplevel)", function() { expect(response.getAllResponseHeaders()).toBe([ "X-Header: header value 1", "X-Header: header value 2" - ].join("\r\n")); + ].join("\r\n") + "\r\n"); }); }); diff --git a/src/fakeRequest.js b/src/fakeRequest.js index 402afcf..4695f28 100644 --- a/src/fakeRequest.js +++ b/src/fakeRequest.js @@ -212,7 +212,7 @@ getJasmineRequireObj().AjaxFakeRequest = function() { responseHeaders.push(this.responseHeaders[i].name + ': ' + this.responseHeaders[i].value); } - return responseHeaders.join('\r\n'); + return responseHeaders.join('\r\n') + '\r\n'; }, responseText: null,