Skip to content

Commit

Permalink
Stub Requests can pass through statusText
Browse files Browse the repository at this point in the history
- Fixes #188
  • Loading branch information
Gregg Van Hove committed May 8, 2018
1 parent eb1a845 commit e811ac8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/mock-ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions spec/integration/webmock-style-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
1 change: 1 addition & 0 deletions src/requestStub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e811ac8

Please sign in to comment.