Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a test for undefined value in OutgoingMessage.setHeader #970

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/parallel/test-http-write-head.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ var s = http.createServer(function(req, res) {
}
assert.ok(threw, 'Non-string names should throw');

// undefined value should throw, via 979d0ca8
threw = false;
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use assert.throws()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just quickly duplicated the section above. I'm open to suggestions here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it would make more sense to use assert.throws() with a validation function like:

function(err) {
  return err instanceof Error && err.message === '`value` required in setHeader("foo", value).';
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truth be told, I think the try/catch is more readable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as it is the same style as the above section, @cjihrig would you object to me merging this in as-is?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brendanashworth go for it.

res.setHeader('foo', undefined);
} catch (e) {
assert.ok(e instanceof Error);
assert.equal(e.message, '`value` required in setHeader("foo", value).');
threw = true;
}
assert.ok(threw, 'Undefined value should throw');

res.writeHead(200, { Test: '2' });
res.end();
});
Expand Down