Skip to content

Commit

Permalink
fix(mockResponse): writeHead() sets headersSent. (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail authored Dec 9, 2024
1 parent 7297984 commit 8618dd8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/mockResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function createResponse(options = {}) {
Object.assign(mockResponse._headers, utils.convertKeysToLowerCase(headers));
}

this.headersSent = true;
return this;
};

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions test/lib/mockResponse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,10 +870,8 @@ describe('mockResponse', () => {

it('updates the headersSent property of the response', () => {
const headers = { 'x-header': 'test llama' };
response.writeHead(400, headers);
// headers are only sent by node with first body byte
expect(response.headersSent).to.equal(false);
response.write('foo');
response.writeHead(400, headers);
expect(response.headersSent).to.equal(true);
// further updates to headers shouldn't really be reflected in mock headers
// since these would be transmitted as part of the body (probably breaking chunked encoding)
Expand Down

0 comments on commit 8618dd8

Please sign in to comment.