Skip to content

Commit

Permalink
Merge pull request #50 from silvermine/expose-body
Browse files Browse the repository at this point in the history
feat: expose Response.body as read-only property
  • Loading branch information
jthomerson authored Apr 10, 2019
2 parents 82b92d2 + 4a889ad commit b0545d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export default class Response {
this._lambdaCallback = cb;
}

/**
* Expose the body of the response as a read-only property so that it can be used in
* places such as after write listeners (for validating or logging the body that was
* sent).
*/
public get body(): string {
return this._body;
}

// METHODS RELATED TO SETTING RESPONSE HEADERS AND CODES THAT DO NOT SEND RESPONSES

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/Response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,15 @@ describe('Response', () => {
});
});

describe('body property', () => {
it('contains what was sent in the response', () => {
const resp = new Response(app, new Request(app, apiGatewayRequest(), handlerContext()), spy());

resp.send({ foo: 'bar' });
expect(resp.body).to.eql(JSON.stringify({ foo: 'bar' }));
});
});

describe('response sending functions', () => {
let cb: SinonSpy, resp: Response;

Expand Down

0 comments on commit b0545d8

Please sign in to comment.