From e811ac826f436042032c577f3d47326f93bc9fdb Mon Sep 17 00:00:00 2001 From: Gregg Van Hove Date: Mon, 7 May 2018 17:35:19 -0700 Subject: [PATCH] Stub Requests can pass through `statusText` - Fixes #188 --- lib/mock-ajax.js | 1 + spec/integration/webmock-style-spec.js | 10 ++++++++++ src/requestStub.js | 1 + 3 files changed, 12 insertions(+) diff --git a/lib/mock-ajax.js b/lib/mock-ajax.js index 7cfea75..c7d2504 100644 --- a/lib/mock-ajax.js +++ b/lib/mock-ajax.js @@ -651,6 +651,7 @@ getJasmineRequireObj().AjaxRequestStub = function() { this.andReturn = function(options) { this.action = RETURN; this.status = (typeof options.status !== 'undefined') ? options.status : 200; + this.statusText = options.statusText; this.contentType = options.contentType; this.response = options.response; diff --git a/spec/integration/webmock-style-spec.js b/spec/integration/webmock-style-spec.js index de0d4db..190b9bd 100644 --- a/spec/integration/webmock-style-spec.js +++ b/spec/integration/webmock-style-spec.js @@ -84,6 +84,16 @@ describe("Webmock style mocking", function() { expect(response.getResponseHeader('X-Custom')).toEqual('header value'); }); + it("shoiuld set the status info", function() { + mockAjax.stubRequest("http://example.com/someApi").andReturn({ + status: 201, + statusText: 'HTTP/1.1 201 CREATED' + }); + sendRequest(fakeGlobal); + expect(response.status).toEqual(201); + expect(response.statusText).toEqual('HTTP/1.1 201 CREATED'); + }); + describe("with another stub for the same url", function() { beforeEach(function() { mockAjax.stubRequest("http://example.com/someApi").andReturn({responseText: "no", status: 403}); diff --git a/src/requestStub.js b/src/requestStub.js index 5fbc88f..be7183e 100644 --- a/src/requestStub.js +++ b/src/requestStub.js @@ -24,6 +24,7 @@ getJasmineRequireObj().AjaxRequestStub = function() { this.andReturn = function(options) { this.action = RETURN; this.status = (typeof options.status !== 'undefined') ? options.status : 200; + this.statusText = options.statusText; this.contentType = options.contentType; this.response = options.response;